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: 400 vol.
ACTIVE: 18 customers
- Berlin Hbf (50 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (35 vol.)
- Stuttgart Hbf (85 vol.)
- Dresden Hbf (35 vol.)
- München Hbf (30 vol.)
- Bremen Hbf (50 vol.)
- Leipzig Hbf (45 vol.)
- Nürnberg Hbf (30 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (60 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (40 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1164.587 km
LOAD: 395 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 30 vol.
- Stuttgart Hbf | 85 vol.
- Mannheim Hbf | 60 vol.
- Mainz Hbf | 75 vol.
- Frankfurt Hbf | 30 vol.
Tour 2
COST: 1628.753 km
LOAD: 390 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 50 vol.
- Aachen Hbf | 35 vol.
- Köln Hbf | 55 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 50 vol.
- Hannover Hbf | 85 vol.
Tour 3
COST: 1355.175 km
LOAD: 180 vol.
- Kiel Hbf | 50 vol.
- Berlin Hbf | 50 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 45 vol.
LOAD: 395 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 30 vol.
- Stuttgart Hbf | 85 vol.
- Mannheim Hbf | 60 vol.
- Mainz Hbf | 75 vol.
- Frankfurt Hbf | 30 vol.
LOAD: 390 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 50 vol.
- Aachen Hbf | 35 vol.
- Köln Hbf | 55 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 50 vol.
- Hannover Hbf | 85 vol.
LOAD: 180 vol.
- Kiel Hbf | 50 vol.
- Berlin Hbf | 50 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 45 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 965 vol. | Vehicle capacity: 400 vol. Loads: [0, 50, 0, 30, 85, 35, 85, 35, 0, 30, 50, 45, 0, 30, 0, 0, 55, 60, 50, 75, 85, 50, 40, 75] ITERATION Generation: #1 Best cost: 5257.651 | Path: [0, 1, 11, 7, 13, 20, 3, 19, 21, 0, 22, 10, 4, 18, 17, 6, 9, 0, 16, 5, 23, 0] Best cost: 4637.800 | Path: [0, 3, 19, 17, 21, 23, 6, 0, 22, 10, 4, 18, 1, 11, 7, 13, 0, 20, 9, 16, 5, 0] Best cost: 4585.400 | Path: [0, 9, 13, 20, 3, 19, 17, 21, 5, 0, 22, 10, 4, 18, 1, 7, 11, 0, 16, 6, 23, 0] Best cost: 4468.351 | Path: [0, 16, 5, 3, 19, 17, 6, 13, 9, 0, 22, 10, 4, 18, 1, 7, 11, 0, 20, 21, 23, 0] Best cost: 4380.047 | Path: [0, 3, 19, 17, 6, 20, 13, 9, 0, 4, 10, 22, 16, 5, 21, 23, 0, 11, 7, 1, 18, 0] Best cost: 4183.928 | Path: [0, 4, 10, 22, 16, 5, 17, 19, 0, 20, 13, 9, 6, 23, 21, 3, 0, 11, 7, 1, 18, 0] Generation: #2 Best cost: 4171.408 | Path: [0, 20, 13, 9, 6, 17, 19, 3, 0, 4, 10, 22, 16, 5, 21, 23, 0, 11, 7, 1, 18, 0] OPTIMIZING each tour... Current: [[0, 20, 13, 9, 6, 17, 19, 3, 0], [0, 4, 10, 22, 16, 5, 21, 23, 0], [0, 11, 7, 1, 18, 0]] [2] Cost: 1646.502 to 1628.753 | Optimized: [0, 23, 21, 5, 16, 22, 10, 4, 0] [3] Cost: 1360.319 to 1355.175 | Optimized: [0, 18, 1, 7, 11, 0] ACO RESULTS [1/395 vol./1164.587 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [2/390 vol./1628.753 km] Kassel-Wilhelmshöhe -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe [3/180 vol./1355.175 km] Kassel-Wilhelmshöhe -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4148.515 km.