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: 300 vol.
ACTIVE: 17 customers
- Kassel-Wilhelmshöhe (85 vol.)
- Düsseldorf Hbf (95 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (40 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (30 vol.)
- Leipzig Hbf (65 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (80 vol.)
- Mannheim Hbf (55 vol.)
- Mainz Hbf (20 vol.)
- Saarbrücken Hbf (85 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 2001.808 km
LOAD: 295 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 85 vol.
- Bremen Hbf | 30 vol.
Tour 2
COST: 1351.104 km
LOAD: 280 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 65 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 60 vol.
Tour 3
COST: 1322.541 km
LOAD: 295 vol.
- Dortmund Hbf | 90 vol.
- Düsseldorf Hbf | 95 vol.
- Aachen Hbf | 40 vol.
- Osnabrück Hbf | 70 vol.
Tour 4
COST: 1006.826 km
LOAD: 225 vol.
- Kassel-Wilhelmshöhe | 85 vol.
- Hannover Hbf | 100 vol.
- Hamburg Hbf | 40 vol.
LOAD: 295 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 85 vol.
- Bremen Hbf | 30 vol.
LOAD: 280 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 65 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 60 vol.
LOAD: 295 vol.
- Dortmund Hbf | 90 vol.
- Düsseldorf Hbf | 95 vol.
- Aachen Hbf | 40 vol.
- Osnabrück Hbf | 70 vol.
LOAD: 225 vol.
- Kassel-Wilhelmshöhe | 85 vol.
- Hannover Hbf | 100 vol.
- Hamburg Hbf | 40 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: [1] Berlin Hbf | Number of cities: 24 | Total loads: 1095 vol. | Vehicle capacity: 300 vol. Loads: [85, 0, 95, 0, 100, 40, 0, 90, 40, 60, 30, 65, 90, 65, 80, 0, 0, 55, 0, 20, 0, 85, 70, 25] ITERATION Generation: #1 Best cost: 6321.086 | Path: [1, 0, 22, 10, 8, 11, 1, 7, 13, 9, 14, 1, 4, 12, 2, 1, 17, 19, 21, 23, 5, 1] Best cost: 5889.101 | Path: [1, 2, 12, 22, 10, 1, 7, 11, 4, 8, 1, 0, 19, 17, 14, 23, 1, 13, 9, 21, 5, 1] Best cost: 5877.658 | Path: [1, 19, 17, 14, 23, 21, 10, 1, 7, 11, 13, 9, 1, 8, 4, 22, 12, 1, 0, 2, 5, 1] Generation: #2 Best cost: 5857.740 | Path: [1, 13, 9, 14, 17, 19, 1, 7, 11, 0, 8, 1, 4, 10, 22, 12, 1, 2, 5, 21, 23, 1] Generation: #3 Best cost: 5840.899 | Path: [1, 2, 12, 22, 10, 1, 7, 11, 4, 8, 1, 13, 9, 14, 17, 19, 1, 0, 5, 21, 23, 1] Best cost: 5799.560 | Path: [1, 19, 17, 14, 23, 21, 10, 1, 7, 11, 4, 8, 1, 22, 12, 2, 5, 1, 0, 13, 9, 1] Generation: #4 Best cost: 5792.731 | Path: [1, 19, 17, 14, 23, 21, 10, 1, 7, 11, 4, 8, 1, 12, 2, 5, 22, 1, 0, 13, 9, 1] Best cost: 5716.297 | Path: [1, 19, 17, 14, 23, 21, 10, 1, 11, 7, 13, 9, 1, 22, 12, 2, 5, 1, 8, 4, 0, 1] OPTIMIZING each tour... Current: [[1, 19, 17, 14, 23, 21, 10, 1], [1, 11, 7, 13, 9, 1], [1, 22, 12, 2, 5, 1], [1, 8, 4, 0, 1]] [2] Cost: 1377.326 to 1351.104 | Optimized: [1, 7, 11, 13, 9, 1] [3] Cost: 1329.370 to 1322.541 | Optimized: [1, 12, 2, 5, 22, 1] [4] Cost: 1007.793 to 1006.826 | Optimized: [1, 0, 4, 8, 1] ACO RESULTS [1/295 vol./2001.808 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Bremen Hbf --> Berlin Hbf [2/280 vol./1351.104 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf [3/295 vol./1322.541 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Osnabrück Hbf --> Berlin Hbf [4/225 vol./1006.826 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5682.279 km.