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 (55 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (25 vol.)
- Dresden Hbf (40 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (45 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (50 vol.)
- Ulm Hbf (75 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (75 vol.)
- Mainz Hbf (70 vol.)
- Würzburg Hbf (65 vol.)
- Saarbrücken Hbf (75 vol.)
- Osnabrück Hbf (25 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1381.35 km
LOAD: 390 vol.
- Leipzig Hbf | 45 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 75 vol.
- Stuttgart Hbf | 25 vol.
- Karlsruhe Hbf | 50 vol.
- Mannheim Hbf | 75 vol.
Tour 2
COST: 1164.248 km
LOAD: 375 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 40 vol.
- Düsseldorf Hbf | 90 vol.
- Dortmund Hbf | 50 vol.
- Osnabrück Hbf | 25 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 20 vol.
- Hannover Hbf | 25 vol.
Tour 3
COST: 1133.701 km
LOAD: 370 vol.
- Frankfurt Hbf | 70 vol.
- Mainz Hbf | 70 vol.
- Saarbrücken Hbf | 75 vol.
- Freiburg Hbf | 90 vol.
- Würzburg Hbf | 65 vol.
Tour 4
COST: 960.522 km
LOAD: 95 vol.
- Dresden Hbf | 40 vol.
- Berlin Hbf | 55 vol.
LOAD: 390 vol.
- Leipzig Hbf | 45 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 75 vol.
- Stuttgart Hbf | 25 vol.
- Karlsruhe Hbf | 50 vol.
- Mannheim Hbf | 75 vol.
LOAD: 375 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 40 vol.
- Düsseldorf Hbf | 90 vol.
- Dortmund Hbf | 50 vol.
- Osnabrück Hbf | 25 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 20 vol.
- Hannover Hbf | 25 vol.
LOAD: 370 vol.
- Frankfurt Hbf | 70 vol.
- Mainz Hbf | 70 vol.
- Saarbrücken Hbf | 75 vol.
- Freiburg Hbf | 90 vol.
- Würzburg Hbf | 65 vol.
LOAD: 95 vol.
- Dresden Hbf | 40 vol.
- Berlin Hbf | 55 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, 55, 90, 70, 25, 40, 25, 40, 20, 95, 55, 45, 50, 25, 50, 75, 70, 75, 0, 70, 65, 75, 25, 90] ITERATION Generation: #1 Best cost: 5667.174 | Path: [0, 1, 7, 11, 13, 20, 3, 19, 6, 0, 4, 10, 22, 12, 2, 16, 5, 8, 0, 17, 14, 15, 9, 23, 0, 21, 0] Best cost: 5319.990 | Path: [0, 3, 19, 17, 14, 6, 15, 13, 0, 12, 2, 16, 5, 21, 20, 0, 22, 10, 8, 4, 11, 7, 1, 9, 0, 23, 0] Best cost: 5247.192 | Path: [0, 11, 7, 1, 4, 22, 10, 8, 12, 16, 0, 2, 5, 19, 3, 17, 14, 0, 20, 13, 9, 15, 6, 21, 0, 23, 0] Best cost: 5097.905 | Path: [0, 17, 14, 6, 15, 9, 13, 11, 0, 12, 2, 16, 5, 21, 3, 0, 22, 10, 4, 8, 1, 7, 20, 19, 0, 23, 0] Best cost: 5022.823 | Path: [0, 7, 11, 1, 8, 10, 4, 22, 12, 16, 0, 19, 3, 17, 14, 6, 15, 13, 0, 20, 9, 23, 21, 5, 0, 2, 0] Best cost: 4800.253 | Path: [0, 17, 14, 6, 15, 9, 13, 11, 0, 12, 2, 16, 5, 22, 4, 10, 8, 0, 3, 19, 21, 23, 20, 0, 7, 1, 0] Best cost: 4677.121 | Path: [0, 17, 14, 6, 15, 9, 13, 11, 0, 4, 8, 10, 22, 12, 2, 16, 5, 0, 3, 19, 21, 23, 20, 0, 7, 1, 0] OPTIMIZING each tour... Current: [[0, 17, 14, 6, 15, 9, 13, 11, 0], [0, 4, 8, 10, 22, 12, 2, 16, 5, 0], [0, 3, 19, 21, 23, 20, 0], [0, 7, 1, 0]] [1] Cost: 1389.343 to 1381.350 | Optimized: [0, 11, 13, 9, 15, 6, 14, 17, 0] [2] Cost: 1193.555 to 1164.248 | Optimized: [0, 16, 5, 2, 12, 22, 10, 8, 4, 0] ACO RESULTS [1/390 vol./1381.350 km] Kassel-Wilhelmshöhe -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe [2/375 vol./1164.248 km] Kassel-Wilhelmshöhe -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe [3/370 vol./1133.701 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [4/ 95 vol./ 960.522 km] Kassel-Wilhelmshöhe -> Dresden Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4639.821 km.