Solving CVRP with ACO
Minimizing Travel Cost for Complex Delivery Problems
This scenario involves the Capacitated Vehicle Routing Problem,
solved using the meta-heuristics algorithm Ant Colony Optimization. Basically, VRP is a network consisting of a number of nodes
(sometimes called cities) and arcs connecting one to all others along with the corresponding costs.
Mostly, the aim is to minimize the cost in visiting each customer once and only once. The term
"capacitated" is added due to some capacity constraints on the vehicles (vcap).
Enter the problem. Some company wants to deliver loads to a number of customers. In this case, we
have 24 nodes based on the location of Germany's train stations (don't ask why). The delivery
always starts from and ends at the depot, visiting a list of customers in other cities. And then
a number of questions arise:
- How do we minimize the travel cost in terms of distance?
- How many trucks are required?
- Which cities are visited by the truck #1, #2. etc.?
- depot: [0..23], def = 0
- vcap: [200..400], def = 400
There is a way to set all the demands, but I don't think you are ready for that. 😉
VCAP: 400 vol.
ACTIVE: 22 customers
- Berlin Hbf (40 vol.)
- Frankfurt Hbf (20 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (20 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (80 vol.)
- Leipzig Hbf (85 vol.)
- Dortmund Hbf (35 vol.)
- Nürnberg Hbf (90 vol.)
- Karlsruhe Hbf (60 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (50 vol.)
- Kiel Hbf (60 vol.)
- Mainz Hbf (50 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1595.471 km
LOAD: 395 vol.
- Frankfurt Hbf | 20 vol.
- Karlsruhe Hbf | 60 vol.
- Stuttgart Hbf | 30 vol.
- Ulm Hbf | 95 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 70 vol.
- Aachen Hbf | 20 vol.
- Köln Hbf | 30 vol.
- Dortmund Hbf | 35 vol.
Tour 2
COST: 937.097 km
LOAD: 375 vol.
- Hannover Hbf | 85 vol.
- Hamburg Hbf | 65 vol.
- Kiel Hbf | 60 vol.
- Bremen Hbf | 80 vol.
- Osnabrück Hbf | 85 vol.
Tour 3
COST: 1632.633 km
LOAD: 360 vol.
- Würzburg Hbf | 30 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 40 vol.
- Leipzig Hbf | 85 vol.
- Dresden Hbf | 75 vol.
- Berlin Hbf | 40 vol.
Tour 4
COST: 582.258 km
LOAD: 100 vol.
- Mannheim Hbf | 50 vol.
- Mainz Hbf | 50 vol.
LOAD: 395 vol.
- Frankfurt Hbf | 20 vol.
- Karlsruhe Hbf | 60 vol.
- Stuttgart Hbf | 30 vol.
- Ulm Hbf | 95 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 70 vol.
- Aachen Hbf | 20 vol.
- Köln Hbf | 30 vol.
- Dortmund Hbf | 35 vol.
LOAD: 375 vol.
- Hannover Hbf | 85 vol.
- Hamburg Hbf | 65 vol.
- Kiel Hbf | 60 vol.
- Bremen Hbf | 80 vol.
- Osnabrück Hbf | 85 vol.
LOAD: 360 vol.
- Würzburg Hbf | 30 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 40 vol.
- Leipzig Hbf | 85 vol.
- Dresden Hbf | 75 vol.
- Berlin Hbf | 40 vol.
LOAD: 100 vol.
- Mannheim Hbf | 50 vol.
- Mainz Hbf | 50 vol.
#generations: 10 for global, 5 for local
#ants: 5 times #active_customers
ACO
Rel. importance of pheromones α = 1.0
Rel. importance of visibility β = 10.0
Trail persistance ρ = 0.5
Pheromone intensity Q = 10
See this wikipedia page to learn more.
NETWORK Depo: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1230 vol. | Vehicle capacity: 400 vol. Loads: [0, 40, 0, 20, 85, 20, 30, 75, 65, 40, 80, 85, 35, 90, 60, 95, 30, 50, 60, 50, 30, 70, 85, 35] ITERATION Generation: #1 Best cost: 5900.595 | Path: [0, 1, 7, 11, 4, 10, 12, 0, 22, 16, 5, 3, 19, 17, 14, 6, 20, 0, 13, 9, 15, 21, 23, 8, 0, 18, 0] Best cost: 5832.392 | Path: [0, 3, 19, 17, 14, 6, 15, 9, 20, 5, 0, 12, 16, 22, 4, 10, 8, 0, 11, 7, 1, 18, 23, 21, 0, 13, 0] Best cost: 5660.467 | Path: [0, 4, 10, 22, 12, 16, 5, 17, 0, 3, 19, 20, 13, 15, 6, 14, 0, 8, 18, 1, 11, 7, 9, 23, 0, 21, 0] Best cost: 5533.417 | Path: [0, 5, 16, 12, 22, 10, 4, 8, 0, 3, 19, 17, 14, 6, 15, 9, 20, 0, 11, 7, 1, 18, 21, 23, 0, 13, 0] Best cost: 5522.564 | Path: [0, 8, 18, 10, 22, 12, 16, 5, 3, 0, 11, 7, 1, 4, 20, 19, 23, 0, 13, 9, 15, 6, 14, 17, 0, 21, 0] Best cost: 5249.921 | Path: [0, 12, 16, 5, 22, 10, 4, 8, 0, 20, 13, 9, 15, 6, 14, 17, 0, 3, 19, 21, 23, 7, 1, 11, 0, 18, 0] Best cost: 5188.986 | Path: [0, 1, 11, 7, 13, 20, 3, 19, 0, 12, 16, 5, 21, 17, 14, 6, 15, 0, 4, 8, 18, 10, 22, 0, 23, 9, 0] Best cost: 4917.147 | Path: [0, 12, 16, 5, 21, 14, 6, 15, 20, 3, 0, 22, 10, 8, 18, 4, 0, 19, 17, 23, 9, 13, 7, 1, 0, 11, 0] Generation: #6 Best cost: 4762.886 | Path: [0, 12, 16, 5, 21, 23, 14, 6, 15, 3, 0, 22, 10, 8, 18, 4, 0, 20, 13, 9, 11, 7, 1, 0, 19, 17, 0] OPTIMIZING each tour... Current: [[0, 12, 16, 5, 21, 23, 14, 6, 15, 3, 0], [0, 22, 10, 8, 18, 4, 0], [0, 20, 13, 9, 11, 7, 1, 0], [0, 19, 17, 0]] [1] Cost: 1603.435 to 1595.471 | Optimized: [0, 3, 14, 6, 15, 23, 21, 5, 16, 12, 0] [2] Cost: 943.835 to 937.097 | Optimized: [0, 4, 8, 18, 10, 22, 0] [4] Cost: 582.983 to 582.258 | Optimized: [0, 17, 19, 0] ACO RESULTS [1/395 vol./1595.471 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [2/375 vol./ 937.097 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf -> Bremen Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe [3/360 vol./1632.633 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Leipzig Hbf -> Dresden Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe [4/100 vol./ 582.258 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4747.459 km.