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: 19 customers
- Berlin Hbf (40 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (50 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (25 vol.)
- Dortmund Hbf (65 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (80 vol.)
- Kiel Hbf (45 vol.)
- Mainz Hbf (85 vol.)
- Saarbrücken Hbf (90 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (40 vol.)
Tour 1
COST: 1446.531 km
LOAD: 380 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 45 vol.
- Berlin Hbf | 40 vol.
- Dresden Hbf | 50 vol.
- Leipzig Hbf | 25 vol.
Tour 2
COST: 1265.901 km
LOAD: 385 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 40 vol.
- Saarbrücken Hbf | 90 vol.
- Aachen Hbf | 45 vol.
- Köln Hbf | 65 vol.
- Dortmund Hbf | 65 vol.
Tour 3
COST: 1155.803 km
LOAD: 325 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 95 vol.
- Mannheim Hbf | 80 vol.
- Mainz Hbf | 85 vol.
Tour 4
COST: 362.286 km
LOAD: 100 vol.
- Hannover Hbf | 100 vol.
LOAD: 380 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 45 vol.
- Berlin Hbf | 40 vol.
- Dresden Hbf | 50 vol.
- Leipzig Hbf | 25 vol.
LOAD: 385 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 40 vol.
- Saarbrücken Hbf | 90 vol.
- Aachen Hbf | 45 vol.
- Köln Hbf | 65 vol.
- Dortmund Hbf | 65 vol.
LOAD: 325 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 95 vol.
- Mannheim Hbf | 80 vol.
- Mainz Hbf | 85 vol.
LOAD: 100 vol.
- Hannover Hbf | 100 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: 1190 vol. | Vehicle capacity: 400 vol. Loads: [0, 40, 0, 0, 100, 45, 95, 50, 100, 25, 100, 25, 65, 0, 80, 40, 65, 80, 45, 85, 0, 90, 20, 40] ITERATION Generation: #1 Best cost: 5744.375 | Path: [0, 1, 7, 11, 10, 4, 22, 12, 0, 19, 17, 14, 6, 15, 0, 16, 5, 21, 23, 9, 8, 0, 18, 0] Best cost: 4931.231 | Path: [0, 4, 22, 10, 8, 18, 11, 0, 12, 16, 5, 17, 14, 23, 9, 0, 19, 21, 6, 15, 7, 1, 0] Best cost: 4807.942 | Path: [0, 16, 12, 22, 10, 8, 18, 0, 4, 11, 1, 7, 9, 15, 6, 0, 19, 17, 14, 23, 21, 0, 5, 0] Best cost: 4783.291 | Path: [0, 17, 14, 6, 15, 9, 7, 11, 0, 12, 16, 5, 19, 21, 23, 0, 4, 22, 10, 8, 18, 0, 1, 0] Best cost: 4634.003 | Path: [0, 17, 14, 6, 15, 9, 7, 11, 0, 4, 8, 18, 10, 22, 0, 12, 16, 5, 19, 21, 23, 0, 1, 0] Generation: #2 Best cost: 4562.868 | Path: [0, 12, 16, 5, 21, 14, 23, 0, 4, 10, 8, 18, 1, 0, 19, 17, 6, 15, 9, 11, 7, 0, 22, 0] Best cost: 4492.758 | Path: [0, 4, 10, 8, 18, 1, 0, 12, 16, 5, 21, 14, 23, 0, 19, 17, 6, 15, 9, 7, 11, 0, 22, 0] Best cost: 4344.794 | Path: [0, 11, 7, 1, 8, 18, 10, 22, 0, 12, 16, 5, 21, 14, 23, 0, 19, 17, 6, 15, 9, 0, 4, 0] OPTIMIZING each tour... Current: [[0, 11, 7, 1, 8, 18, 10, 22, 0], [0, 12, 16, 5, 21, 14, 23, 0], [0, 19, 17, 6, 15, 9, 0], [0, 4, 0]] [1] Cost: 1473.548 to 1446.531 | Optimized: [0, 22, 10, 8, 18, 1, 7, 11, 0] [2] Cost: 1333.628 to 1265.901 | Optimized: [0, 14, 23, 21, 5, 16, 12, 0] [3] Cost: 1175.332 to 1155.803 | Optimized: [0, 9, 15, 6, 17, 19, 0] ACO RESULTS [1/380 vol./1446.531 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/385 vol./1265.901 km] Kassel-Wilhelmshöhe -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [3/325 vol./1155.803 km] Kassel-Wilhelmshöhe -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe [4/100 vol./ 362.286 km] Kassel-Wilhelmshöhe -> Hannover Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4230.521 km.