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: 20 customers
- Kassel-Wilhelmshöhe (100 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (20 vol.)
- Aachen Hbf (55 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (65 vol.)
- Bremen Hbf (30 vol.)
- Leipzig Hbf (90 vol.)
- Dortmund Hbf (25 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (75 vol.)
- Köln Hbf (80 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (95 vol.)
- Osnabrück Hbf (95 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1834.995 km
LOAD: 290 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 75 vol.
- Stuttgart Hbf | 20 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 75 vol.
Tour 2
COST: 1377.153 km
LOAD: 290 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 90 vol.
- Nürnberg Hbf | 25 vol.
- Würzburg Hbf | 95 vol.
- Frankfurt Hbf | 55 vol.
Tour 3
COST: 1348.041 km
LOAD: 275 vol.
- Dortmund Hbf | 25 vol.
- Aachen Hbf | 55 vol.
- Köln Hbf | 80 vol.
- Osnabrück Hbf | 95 vol.
- Hannover Hbf | 20 vol.
Tour 4
COST: 959.498 km
LOAD: 215 vol.
- Hamburg Hbf | 90 vol.
- Bremen Hbf | 30 vol.
- Kiel Hbf | 95 vol.
Tour 5
COST: 1189.42 km
LOAD: 195 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Mainz Hbf | 95 vol.
LOAD: 290 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 75 vol.
- Stuttgart Hbf | 20 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 75 vol.
LOAD: 290 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 90 vol.
- Nürnberg Hbf | 25 vol.
- Würzburg Hbf | 95 vol.
- Frankfurt Hbf | 55 vol.
LOAD: 275 vol.
- Dortmund Hbf | 25 vol.
- Aachen Hbf | 55 vol.
- Köln Hbf | 80 vol.
- Osnabrück Hbf | 95 vol.
- Hannover Hbf | 20 vol.
LOAD: 215 vol.
- Hamburg Hbf | 90 vol.
- Bremen Hbf | 30 vol.
- Kiel Hbf | 95 vol.
LOAD: 195 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Mainz Hbf | 95 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: 1265 vol. | Vehicle capacity: 300 vol. Loads: [100, 0, 0, 55, 20, 55, 20, 25, 90, 65, 30, 90, 25, 25, 55, 75, 80, 0, 95, 95, 95, 0, 95, 75] ITERATION Generation: #1 Best cost: 8291.608 | Path: [1, 0, 12, 16, 5, 10, 1, 11, 7, 4, 22, 3, 1, 8, 18, 6, 15, 1, 13, 20, 14, 23, 1, 9, 19, 1] Best cost: 7869.777 | Path: [1, 3, 19, 14, 6, 15, 1, 11, 7, 13, 20, 9, 1, 8, 18, 4, 10, 12, 1, 0, 22, 16, 1, 5, 23, 1] Best cost: 7791.145 | Path: [1, 5, 16, 12, 22, 10, 1, 11, 7, 20, 3, 13, 1, 8, 18, 4, 19, 1, 0, 14, 6, 15, 1, 9, 23, 1] Best cost: 7681.367 | Path: [1, 6, 15, 14, 23, 3, 4, 1, 11, 7, 13, 20, 9, 1, 8, 18, 10, 12, 5, 1, 22, 0, 16, 1, 19, 1] Best cost: 7454.447 | Path: [1, 9, 15, 6, 14, 23, 1, 7, 11, 4, 10, 8, 12, 1, 20, 13, 3, 19, 1, 18, 22, 0, 1, 16, 5, 1] Best cost: 7443.795 | Path: [1, 20, 13, 9, 15, 6, 4, 1, 11, 7, 10, 22, 12, 1, 18, 8, 0, 1, 3, 19, 14, 23, 1, 16, 5, 1] Best cost: 7183.695 | Path: [1, 23, 14, 6, 15, 9, 1, 11, 7, 4, 22, 12, 10, 1, 13, 20, 3, 19, 1, 8, 18, 0, 1, 16, 5, 1] Best cost: 7133.981 | Path: [1, 9, 15, 6, 14, 23, 1, 7, 11, 0, 4, 10, 12, 1, 8, 18, 22, 1, 13, 20, 3, 19, 1, 5, 16, 1] Best cost: 7047.446 | Path: [1, 13, 20, 6, 14, 23, 12, 1, 7, 11, 4, 10, 8, 1, 18, 22, 0, 1, 3, 19, 16, 5, 1, 9, 15, 1] Best cost: 6981.725 | Path: [1, 9, 15, 6, 14, 23, 1, 7, 11, 4, 10, 22, 12, 1, 8, 18, 0, 1, 5, 16, 19, 3, 1, 13, 20, 1] Best cost: 6920.965 | Path: [1, 16, 5, 12, 22, 10, 1, 8, 18, 4, 11, 1, 7, 13, 20, 3, 19, 1, 0, 23, 14, 6, 1, 9, 15, 1] Generation: #2 Best cost: 6918.710 | Path: [1, 9, 15, 6, 14, 23, 1, 7, 11, 13, 20, 3, 1, 0, 12, 16, 5, 4, 1, 8, 18, 10, 1, 22, 19, 1] Generation: #3 Best cost: 6778.879 | Path: [1, 23, 14, 6, 15, 9, 1, 11, 7, 13, 20, 3, 1, 4, 22, 12, 16, 5, 1, 8, 18, 10, 1, 0, 19, 1] OPTIMIZING each tour... Current: [[1, 23, 14, 6, 15, 9, 1], [1, 11, 7, 13, 20, 3, 1], [1, 4, 22, 12, 16, 5, 1], [1, 8, 18, 10, 1], [1, 0, 19, 1]] [1] Cost: 1850.858 to 1834.995 | Optimized: [1, 9, 15, 6, 14, 23, 1] [2] Cost: 1403.375 to 1377.153 | Optimized: [1, 7, 11, 13, 20, 3, 1] [3] Cost: 1360.161 to 1348.041 | Optimized: [1, 12, 5, 16, 22, 4, 1] [4] Cost: 975.065 to 959.498 | Optimized: [1, 8, 10, 18, 1] ACO RESULTS [1/290 vol./1834.995 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [2/290 vol./1377.153 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> Würzburg Hbf -> Frankfurt Hbf --> Berlin Hbf [3/275 vol./1348.041 km] Berlin Hbf -> Dortmund Hbf -> Aachen Hbf -> Köln Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [4/215 vol./ 959.498 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [5/195 vol./1189.420 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Mainz Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6709.107 km.