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: 23 customers
- Kassel-Wilhelmshöhe (70 vol.)
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (60 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (90 vol.)
- Dresden Hbf (30 vol.)
- Hamburg Hbf (30 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (65 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (70 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (35 vol.)
- Köln Hbf (80 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (90 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (55 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1341.989 km
LOAD: 285 vol.
- Köln Hbf | 80 vol.
- Aachen Hbf | 60 vol.
- Düsseldorf Hbf | 35 vol.
- Dortmund Hbf | 55 vol.
- Osnabrück Hbf | 55 vol.
Tour 2
COST: 1997.549 km
LOAD: 300 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 90 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 20 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 30 vol.
Tour 3
COST: 972.057 km
LOAD: 250 vol.
- Hannover Hbf | 60 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 95 vol.
Tour 4
COST: 1336.583 km
LOAD: 300 vol.
- Mannheim Hbf | 70 vol.
- Mainz Hbf | 90 vol.
- Frankfurt Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 70 vol.
Tour 5
COST: 1556.979 km
LOAD: 225 vol.
- Saarbrücken Hbf | 60 vol.
- Würzburg Hbf | 95 vol.
- Nürnberg Hbf | 70 vol.
LOAD: 285 vol.
- Köln Hbf | 80 vol.
- Aachen Hbf | 60 vol.
- Düsseldorf Hbf | 35 vol.
- Dortmund Hbf | 55 vol.
- Osnabrück Hbf | 55 vol.
LOAD: 300 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 90 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 20 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 30 vol.
LOAD: 250 vol.
- Hannover Hbf | 60 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 95 vol.
LOAD: 300 vol.
- Mannheim Hbf | 70 vol.
- Mainz Hbf | 90 vol.
- Frankfurt Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 70 vol.
LOAD: 225 vol.
- Saarbrücken Hbf | 60 vol.
- Würzburg Hbf | 95 vol.
- Nürnberg Hbf | 70 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: 1360 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 35, 70, 60, 60, 90, 30, 30, 40, 65, 40, 55, 70, 45, 35, 80, 70, 95, 90, 95, 60, 55, 20] ITERATION Generation: #1 Best cost: 8525.225 | Path: [1, 0, 12, 2, 16, 5, 1, 11, 7, 13, 20, 15, 23, 1, 18, 8, 10, 4, 14, 1, 3, 19, 17, 21, 1, 22, 6, 9, 1] Best cost: 8283.189 | Path: [1, 2, 16, 5, 12, 22, 1, 7, 11, 20, 19, 14, 1, 4, 10, 8, 18, 15, 1, 0, 3, 17, 21, 23, 1, 13, 9, 6, 1] Best cost: 7930.722 | Path: [1, 3, 19, 17, 14, 23, 1, 7, 11, 4, 10, 8, 22, 1, 18, 2, 16, 5, 1, 0, 12, 21, 20, 1, 13, 15, 6, 9, 1] Best cost: 7743.111 | Path: [1, 8, 18, 10, 22, 12, 1, 11, 7, 13, 20, 14, 23, 1, 4, 16, 2, 5, 21, 1, 0, 3, 19, 17, 1, 15, 6, 9, 1] Best cost: 7740.564 | Path: [1, 17, 14, 6, 15, 9, 23, 1, 7, 11, 0, 22, 12, 2, 1, 4, 10, 8, 18, 1, 13, 20, 3, 21, 1, 5, 16, 19, 1] Best cost: 7559.868 | Path: [1, 18, 8, 10, 4, 11, 1, 7, 13, 20, 19, 1, 0, 12, 2, 16, 5, 1, 22, 3, 17, 14, 23, 15, 1, 9, 6, 21, 1] Best cost: 7366.545 | Path: [1, 10, 8, 18, 4, 11, 1, 7, 13, 20, 6, 1, 22, 12, 2, 16, 5, 1, 0, 3, 19, 17, 1, 9, 15, 14, 23, 21, 1] Best cost: 7303.656 | Path: [1, 18, 8, 10, 4, 11, 1, 7, 13, 20, 19, 1, 22, 12, 2, 16, 5, 1, 0, 3, 17, 14, 23, 1, 9, 15, 6, 21, 1] Generation: #2 Best cost: 7264.475 | Path: [1, 2, 16, 5, 12, 22, 1, 11, 7, 9, 15, 6, 14, 23, 1, 4, 10, 8, 18, 1, 0, 3, 19, 17, 1, 13, 20, 21, 1] OPTIMIZING each tour... Current: [[1, 2, 16, 5, 12, 22, 1], [1, 11, 7, 9, 15, 6, 14, 23, 1], [1, 4, 10, 8, 18, 1], [1, 0, 3, 19, 17, 1], [1, 13, 20, 21, 1]] [1] Cost: 1369.097 to 1341.989 | Optimized: [1, 16, 5, 2, 12, 22, 1] [2] Cost: 2022.382 to 1997.549 | Optimized: [1, 9, 15, 6, 14, 23, 11, 7, 1] [4] Cost: 1338.208 to 1336.583 | Optimized: [1, 17, 19, 3, 0, 1] [5] Cost: 1562.731 to 1556.979 | Optimized: [1, 21, 20, 13, 1] ACO RESULTS [1/285 vol./1341.989 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Berlin Hbf [2/300 vol./1997.549 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/250 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/300 vol./1336.583 km] Berlin Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [5/225 vol./1556.979 km] Berlin Hbf -> Saarbrücken Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7205.157 km.