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 (50 vol.)
- Hannover Hbf (25 vol.)
- Stuttgart Hbf (35 vol.)
- Dresden Hbf (50 vol.)
- Hamburg Hbf (55 vol.)
- München Hbf (45 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (45 vol.)
- Dortmund Hbf (40 vol.)
- Karlsruhe Hbf (30 vol.)
- Ulm Hbf (35 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (30 vol.)
- Mainz Hbf (95 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1588.69 km
LOAD: 290 vol.
- Dortmund Hbf | 40 vol.
- Köln Hbf | 95 vol.
- Mainz Hbf | 95 vol.
- Mannheim Hbf | 30 vol.
- Karlsruhe Hbf | 30 vol.
Tour 2
COST: 1239.854 km
LOAD: 285 vol.
- Dresden Hbf | 50 vol.
- Leipzig Hbf | 45 vol.
- Hannover Hbf | 25 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 55 vol.
Tour 3
COST: 2001.811 km
LOAD: 215 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 35 vol.
- Freiburg Hbf | 20 vol.
- Saarbrücken Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 50 vol.
LOAD: 290 vol.
- Dortmund Hbf | 40 vol.
- Köln Hbf | 95 vol.
- Mainz Hbf | 95 vol.
- Mannheim Hbf | 30 vol.
- Karlsruhe Hbf | 30 vol.
LOAD: 285 vol.
- Dresden Hbf | 50 vol.
- Leipzig Hbf | 45 vol.
- Hannover Hbf | 25 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 55 vol.
LOAD: 215 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 35 vol.
- Freiburg Hbf | 20 vol.
- Saarbrücken Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 50 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: 790 vol. | Vehicle capacity: 300 vol. Loads: [50, 0, 0, 0, 25, 0, 35, 50, 55, 45, 90, 45, 40, 0, 30, 35, 95, 30, 0, 95, 0, 30, 20, 20] ITERATION Generation: #1 Best cost: 5532.440 | Path: [1, 0, 12, 16, 19, 23, 1, 7, 11, 4, 10, 8, 22, 1, 17, 14, 6, 15, 9, 21, 1] Best cost: 5200.486 | Path: [1, 4, 22, 12, 16, 19, 23, 1, 7, 11, 0, 10, 8, 1, 15, 6, 14, 17, 21, 9, 1] Best cost: 5089.559 | Path: [1, 12, 16, 22, 10, 8, 1, 11, 7, 9, 15, 6, 14, 17, 21, 1, 4, 0, 19, 23, 1] Best cost: 5087.836 | Path: [1, 16, 12, 22, 10, 8, 1, 7, 11, 4, 0, 19, 17, 1, 6, 14, 23, 21, 15, 9, 1] Best cost: 4968.315 | Path: [1, 17, 14, 6, 15, 9, 23, 21, 12, 22, 1, 7, 11, 4, 10, 8, 1, 0, 19, 16, 1] Generation: #2 Best cost: 4965.079 | Path: [1, 16, 12, 22, 10, 8, 1, 7, 11, 4, 0, 19, 17, 1, 9, 15, 6, 14, 23, 21, 1] Best cost: 4842.016 | Path: [1, 12, 16, 19, 17, 14, 1, 7, 11, 4, 22, 10, 8, 1, 0, 21, 23, 6, 15, 9, 1] OPTIMIZING each tour... Current: [[1, 12, 16, 19, 17, 14, 1], [1, 7, 11, 4, 22, 10, 8, 1], [1, 0, 21, 23, 6, 15, 9, 1]] [3] Cost: 2013.472 to 2001.811 | Optimized: [1, 9, 15, 6, 23, 21, 0, 1] ACO RESULTS [1/290 vol./1588.690 km] Berlin Hbf -> Dortmund Hbf -> Köln Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf --> Berlin Hbf [2/285 vol./1239.854 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/215 vol./2001.811 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4830.355 km.