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: 19 customers
- Kassel-Wilhelmshöhe (40 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (60 vol.)
- Aachen Hbf (65 vol.)
- Stuttgart Hbf (55 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (60 vol.)
- München Hbf (20 vol.)
- Bremen Hbf (85 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (75 vol.)
- Köln Hbf (70 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (65 vol.)
- Würzburg Hbf (35 vol.)
- Saarbrücken Hbf (95 vol.)
- Osnabrück Hbf (90 vol.)
Tour 1
COST: 1479.941 km
LOAD: 290 vol.
- Mainz Hbf | 65 vol.
- Aachen Hbf | 65 vol.
- Köln Hbf | 70 vol.
- Düsseldorf Hbf | 90 vol.
Tour 2
COST: 1537.673 km
LOAD: 285 vol.
- München Hbf | 20 vol.
- Ulm Hbf | 75 vol.
- Stuttgart Hbf | 55 vol.
- Nürnberg Hbf | 40 vol.
- Dresden Hbf | 95 vol.
Tour 3
COST: 972.057 km
LOAD: 275 vol.
- Hannover Hbf | 60 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 70 vol.
Tour 4
COST: 1552.431 km
LOAD: 280 vol.
- Würzburg Hbf | 35 vol.
- Karlsruhe Hbf | 80 vol.
- Saarbrücken Hbf | 95 vol.
- Frankfurt Hbf | 70 vol.
Tour 5
COST: 984.722 km
LOAD: 130 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Osnabrück Hbf | 90 vol.
LOAD: 290 vol.
- Mainz Hbf | 65 vol.
- Aachen Hbf | 65 vol.
- Köln Hbf | 70 vol.
- Düsseldorf Hbf | 90 vol.
LOAD: 285 vol.
- München Hbf | 20 vol.
- Ulm Hbf | 75 vol.
- Stuttgart Hbf | 55 vol.
- Nürnberg Hbf | 40 vol.
- Dresden Hbf | 95 vol.
LOAD: 275 vol.
- Hannover Hbf | 60 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 70 vol.
LOAD: 280 vol.
- Würzburg Hbf | 35 vol.
- Karlsruhe Hbf | 80 vol.
- Saarbrücken Hbf | 95 vol.
- Frankfurt Hbf | 70 vol.
LOAD: 130 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Osnabrück Hbf | 90 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: 1260 vol. | Vehicle capacity: 300 vol. Loads: [40, 0, 90, 70, 60, 65, 55, 95, 60, 20, 85, 0, 0, 40, 80, 75, 70, 0, 70, 65, 35, 95, 90, 0] ITERATION Generation: #1 Best cost: 8560.973 | Path: [1, 0, 22, 10, 8, 9, 1, 7, 13, 20, 14, 1, 18, 4, 2, 16, 1, 5, 19, 3, 6, 1, 15, 21, 1] Best cost: 7353.379 | Path: [1, 2, 16, 5, 19, 1, 7, 13, 20, 6, 15, 1, 4, 22, 10, 8, 1, 18, 0, 3, 14, 9, 1, 21, 1] Best cost: 7015.883 | Path: [1, 7, 20, 13, 9, 15, 1, 18, 8, 10, 4, 1, 0, 22, 16, 2, 1, 3, 19, 14, 6, 1, 5, 21, 1] Best cost: 6923.815 | Path: [1, 9, 15, 6, 14, 19, 1, 7, 13, 20, 3, 0, 1, 8, 18, 4, 10, 1, 22, 2, 16, 1, 5, 21, 1] Best cost: 6785.069 | Path: [1, 9, 15, 6, 14, 3, 1, 7, 13, 20, 19, 0, 1, 4, 10, 8, 18, 1, 22, 2, 16, 1, 5, 21, 1] Best cost: 6756.671 | Path: [1, 9, 15, 6, 14, 19, 1, 7, 13, 20, 3, 0, 1, 4, 10, 8, 18, 1, 22, 2, 16, 1, 5, 21, 1] Best cost: 6752.711 | Path: [1, 9, 15, 6, 14, 19, 1, 7, 13, 20, 3, 0, 1, 4, 10, 8, 18, 1, 22, 2, 16, 1, 21, 5, 1] Generation: #3 Best cost: 6750.501 | Path: [1, 9, 15, 6, 14, 19, 1, 7, 13, 20, 3, 0, 1, 18, 8, 10, 4, 1, 21, 5, 2, 1, 22, 16, 1] Generation: #4 Best cost: 6612.839 | Path: [1, 2, 16, 5, 19, 1, 7, 13, 9, 15, 6, 1, 8, 18, 10, 4, 1, 21, 14, 3, 20, 1, 22, 0, 1] OPTIMIZING each tour... Current: [[1, 2, 16, 5, 19, 1], [1, 7, 13, 9, 15, 6, 1], [1, 8, 18, 10, 4, 1], [1, 21, 14, 3, 20, 1], [1, 22, 0, 1]] [1] Cost: 1482.327 to 1479.941 | Optimized: [1, 19, 5, 16, 2, 1] [2] Cost: 1546.120 to 1537.673 | Optimized: [1, 9, 15, 6, 13, 7, 1] [3] Cost: 992.078 to 972.057 | Optimized: [1, 4, 10, 8, 18, 1] [4] Cost: 1606.586 to 1552.431 | Optimized: [1, 20, 14, 21, 3, 1] [5] Cost: 985.728 to 984.722 | Optimized: [1, 0, 22, 1] ACO RESULTS [1/290 vol./1479.941 km] Berlin Hbf -> Mainz Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf [2/285 vol./1537.673 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/275 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/280 vol./1552.431 km] Berlin Hbf -> Würzburg Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf -> Frankfurt Hbf --> Berlin Hbf [5/130 vol./ 984.722 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6526.824 km.