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: 21 customers
- Berlin Hbf (75 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (35 vol.)
- Dresden Hbf (80 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (75 vol.)
- Mainz Hbf (90 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 967.444 km
LOAD: 390 vol.
- Mainz Hbf | 90 vol.
- Saarbrücken Hbf | 50 vol.
- Aachen Hbf | 100 vol.
- Köln Hbf | 60 vol.
- Dortmund Hbf | 90 vol.
Tour 2
COST: 1049.558 km
LOAD: 390 vol.
- Frankfurt Hbf | 95 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 75 vol.
- Stuttgart Hbf | 35 vol.
- Würzburg Hbf | 30 vol.
Tour 3
COST: 1096.971 km
LOAD: 365 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 85 vol.
- Hannover Hbf | 95 vol.
- Leipzig Hbf | 20 vol.
Tour 4
COST: 1619.375 km
LOAD: 395 vol.
- Berlin Hbf | 75 vol.
- Dresden Hbf | 80 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 80 vol.
LOAD: 390 vol.
- Mainz Hbf | 90 vol.
- Saarbrücken Hbf | 50 vol.
- Aachen Hbf | 100 vol.
- Köln Hbf | 60 vol.
- Dortmund Hbf | 90 vol.
LOAD: 390 vol.
- Frankfurt Hbf | 95 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 75 vol.
- Stuttgart Hbf | 35 vol.
- Würzburg Hbf | 30 vol.
LOAD: 365 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 85 vol.
- Hannover Hbf | 95 vol.
- Leipzig Hbf | 20 vol.
LOAD: 395 vol.
- Berlin Hbf | 75 vol.
- Dresden Hbf | 80 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 80 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: 1540 vol. | Vehicle capacity: 400 vol. Loads: [0, 75, 0, 95, 95, 100, 35, 80, 85, 80, 95, 20, 90, 80, 80, 80, 60, 75, 0, 90, 30, 50, 70, 75] ITERATION Generation: #1 Best cost: 5638.171 | Path: [0, 1, 7, 11, 8, 10, 20, 0, 12, 5, 16, 19, 21, 0, 22, 4, 3, 17, 6, 0, 13, 9, 15, 14, 23, 0] Best cost: 5477.875 | Path: [0, 3, 19, 17, 14, 6, 11, 0, 22, 4, 10, 8, 20, 0, 12, 16, 5, 21, 23, 0, 7, 1, 13, 9, 15, 0] Best cost: 5425.524 | Path: [0, 8, 10, 22, 12, 16, 0, 19, 3, 17, 14, 6, 11, 0, 4, 1, 7, 20, 13, 0, 5, 21, 23, 15, 9, 0] Best cost: 5390.754 | Path: [0, 23, 14, 17, 3, 20, 6, 0, 12, 16, 5, 21, 19, 0, 22, 10, 4, 8, 11, 0, 13, 9, 15, 1, 7, 0] Best cost: 5075.835 | Path: [0, 8, 10, 22, 12, 16, 0, 4, 11, 7, 1, 13, 20, 0, 3, 19, 17, 14, 6, 0, 5, 21, 23, 15, 9, 0] Best cost: 5008.943 | Path: [0, 1, 11, 7, 13, 20, 6, 14, 0, 12, 16, 5, 3, 21, 0, 22, 10, 8, 4, 0, 19, 17, 23, 15, 9, 0] Best cost: 4979.297 | Path: [0, 22, 12, 16, 5, 21, 20, 0, 4, 10, 8, 1, 11, 0, 3, 19, 17, 14, 6, 0, 7, 13, 9, 15, 23, 0] Generation: #2 Best cost: 4970.748 | Path: [0, 8, 10, 22, 12, 16, 0, 4, 1, 11, 7, 13, 20, 0, 3, 19, 17, 14, 6, 0, 5, 21, 23, 15, 9, 0] Generation: #8 Best cost: 4960.328 | Path: [0, 12, 16, 5, 19, 21, 0, 3, 17, 14, 23, 6, 20, 0, 22, 10, 8, 4, 11, 0, 13, 9, 15, 7, 1, 0] OPTIMIZING each tour... Current: [[0, 12, 16, 5, 19, 21, 0], [0, 3, 17, 14, 23, 6, 20, 0], [0, 22, 10, 8, 4, 11, 0], [0, 13, 9, 15, 7, 1, 0]] [1] Cost: 1097.874 to 967.444 | Optimized: [0, 19, 21, 5, 16, 12, 0] [4] Cost: 1715.925 to 1619.375 | Optimized: [0, 1, 7, 13, 9, 15, 0] ACO RESULTS [1/390 vol./ 967.444 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [2/390 vol./1049.558 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [3/365 vol./1096.971 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Hannover Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [4/395 vol./1619.375 km] Kassel-Wilhelmshöhe -> Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4733.348 km.