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: 17 customers
- Berlin Hbf (75 vol.)
- Düsseldorf Hbf (50 vol.)
- Frankfurt Hbf (65 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (60 vol.)
- München Hbf (30 vol.)
- Bremen Hbf (80 vol.)
- Nürnberg Hbf (75 vol.)
- Ulm Hbf (85 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (55 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (100 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1372.794 km
LOAD: 380 vol.
- Würzburg Hbf | 60 vol.
- Stuttgart Hbf | 20 vol.
- Freiburg Hbf | 50 vol.
- Saarbrücken Hbf | 100 vol.
- Aachen Hbf | 70 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 50 vol.
Tour 2
COST: 1164.937 km
LOAD: 345 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 85 vol.
- Mannheim Hbf | 55 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 65 vol.
Tour 3
COST: 1420.915 km
LOAD: 285 vol.
- Dresden Hbf | 60 vol.
- Berlin Hbf | 75 vol.
- Kiel Hbf | 70 vol.
- Bremen Hbf | 80 vol.
LOAD: 380 vol.
- Würzburg Hbf | 60 vol.
- Stuttgart Hbf | 20 vol.
- Freiburg Hbf | 50 vol.
- Saarbrücken Hbf | 100 vol.
- Aachen Hbf | 70 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 50 vol.
LOAD: 345 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 85 vol.
- Mannheim Hbf | 55 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 65 vol.
LOAD: 285 vol.
- Dresden Hbf | 60 vol.
- Berlin Hbf | 75 vol.
- Kiel Hbf | 70 vol.
- Bremen 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: 1010 vol. | Vehicle capacity: 400 vol. Loads: [0, 75, 50, 65, 0, 70, 20, 60, 0, 30, 80, 0, 0, 75, 0, 85, 30, 55, 70, 35, 60, 100, 0, 50] ITERATION Generation: #1 Best cost: 5198.521 | Path: [0, 1, 7, 13, 20, 3, 19, 16, 0, 2, 5, 21, 17, 6, 15, 0, 10, 18, 9, 23, 0] Best cost: 4713.799 | Path: [0, 2, 16, 5, 21, 17, 19, 20, 0, 3, 6, 15, 9, 13, 7, 23, 0, 10, 18, 1, 0] Best cost: 4541.865 | Path: [0, 5, 16, 2, 19, 3, 17, 6, 20, 0, 10, 18, 1, 7, 13, 9, 0, 21, 23, 15, 0] Best cost: 4257.320 | Path: [0, 7, 1, 18, 10, 2, 16, 19, 0, 3, 17, 6, 15, 9, 13, 20, 0, 5, 21, 23, 0] Best cost: 4225.709 | Path: [0, 16, 2, 5, 21, 17, 19, 20, 0, 3, 23, 6, 15, 9, 13, 7, 0, 10, 18, 1, 0] Best cost: 4220.680 | Path: [0, 6, 15, 20, 13, 9, 23, 17, 0, 2, 16, 5, 21, 19, 3, 0, 10, 18, 1, 7, 0] Generation: #2 Best cost: 4056.575 | Path: [0, 2, 16, 5, 21, 23, 6, 17, 0, 3, 19, 20, 13, 9, 15, 0, 10, 18, 1, 7, 0] Generation: #3 Best cost: 3997.112 | Path: [0, 16, 2, 5, 21, 23, 6, 20, 0, 3, 19, 17, 15, 9, 13, 0, 10, 18, 1, 7, 0] Generation: #4 Best cost: 3977.586 | Path: [0, 2, 16, 5, 21, 23, 6, 20, 0, 3, 19, 17, 15, 9, 13, 0, 10, 18, 1, 7, 0] OPTIMIZING each tour... Current: [[0, 2, 16, 5, 21, 23, 6, 20, 0], [0, 3, 19, 17, 15, 9, 13, 0], [0, 10, 18, 1, 7, 0]] [1] Cost: 1377.962 to 1372.794 | Optimized: [0, 20, 6, 23, 21, 5, 16, 2, 0] [2] Cost: 1178.603 to 1164.937 | Optimized: [0, 13, 9, 15, 17, 19, 3, 0] [3] Cost: 1421.021 to 1420.915 | Optimized: [0, 7, 1, 18, 10, 0] ACO RESULTS [1/380 vol./1372.794 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe [2/345 vol./1164.937 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/285 vol./1420.915 km] Kassel-Wilhelmshöhe -> Dresden Hbf -> Berlin Hbf -> Kiel Hbf -> Bremen Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3958.646 km.