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 (20 vol.)
- Frankfurt Hbf (35 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (85 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (30 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (80 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (70 vol.)
- Ulm Hbf (55 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (70 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (80 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 1751.636 km
LOAD: 285 vol.
- Mannheim Hbf | 100 vol.
- Karlsruhe Hbf | 70 vol.
- Freiburg Hbf | 55 vol.
- Saarbrücken Hbf | 60 vol.
Tour 2
COST: 1187.501 km
LOAD: 300 vol.
- Würzburg Hbf | 70 vol.
- Nürnberg Hbf | 65 vol.
- Leipzig Hbf | 80 vol.
- Dresden Hbf | 85 vol.
Tour 3
COST: 1657.966 km
LOAD: 290 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 95 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 35 vol.
- Kassel-Wilhelmshöhe | 20 vol.
Tour 4
COST: 1587.416 km
LOAD: 300 vol.
- Aachen Hbf | 85 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 70 vol.
Tour 5
COST: 565.96 km
LOAD: 100 vol.
- Hannover Hbf | 100 vol.
LOAD: 285 vol.
- Mannheim Hbf | 100 vol.
- Karlsruhe Hbf | 70 vol.
- Freiburg Hbf | 55 vol.
- Saarbrücken Hbf | 60 vol.
LOAD: 300 vol.
- Würzburg Hbf | 70 vol.
- Nürnberg Hbf | 65 vol.
- Leipzig Hbf | 80 vol.
- Dresden Hbf | 85 vol.
LOAD: 290 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 95 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 35 vol.
- Kassel-Wilhelmshöhe | 20 vol.
LOAD: 300 vol.
- Aachen Hbf | 85 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 70 vol.
LOAD: 100 vol.
- Hannover Hbf | 100 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: 1275 vol. | Vehicle capacity: 300 vol. Loads: [20, 0, 0, 35, 100, 85, 95, 85, 30, 60, 35, 80, 0, 65, 70, 55, 0, 100, 70, 25, 70, 60, 80, 55] ITERATION Generation: #1 Best cost: 8222.162 | Path: [1, 0, 22, 10, 8, 18, 3, 19, 1, 4, 11, 7, 1, 13, 20, 6, 14, 1, 21, 17, 23, 15, 1, 9, 5, 1] Best cost: 7630.303 | Path: [1, 3, 19, 17, 14, 23, 1, 11, 7, 13, 20, 1, 8, 18, 4, 10, 0, 1, 22, 5, 21, 15, 1, 9, 6, 1] Best cost: 7615.078 | Path: [1, 13, 20, 3, 19, 17, 1, 7, 11, 4, 10, 1, 8, 18, 22, 0, 5, 1, 9, 15, 6, 14, 1, 21, 23, 1] Best cost: 7597.887 | Path: [1, 14, 17, 3, 19, 20, 1, 7, 11, 4, 10, 1, 8, 18, 22, 0, 5, 1, 13, 9, 15, 6, 1, 21, 23, 1] Best cost: 7593.903 | Path: [1, 3, 19, 17, 14, 23, 1, 11, 7, 0, 22, 10, 1, 8, 18, 4, 20, 1, 13, 9, 15, 6, 1, 5, 21, 1] Best cost: 7548.022 | Path: [1, 9, 15, 6, 14, 0, 1, 7, 11, 13, 20, 1, 8, 18, 10, 22, 5, 1, 4, 3, 19, 17, 1, 23, 21, 1] Best cost: 7539.471 | Path: [1, 18, 8, 10, 22, 0, 3, 19, 1, 7, 11, 13, 20, 1, 4, 5, 21, 23, 1, 6, 14, 17, 1, 9, 15, 1] Best cost: 7407.992 | Path: [1, 23, 14, 17, 19, 3, 1, 7, 11, 4, 10, 1, 18, 8, 22, 0, 20, 1, 13, 6, 15, 9, 1, 21, 5, 1] Best cost: 7212.579 | Path: [1, 7, 11, 0, 4, 1, 8, 18, 10, 22, 5, 1, 13, 20, 3, 19, 17, 1, 6, 14, 23, 21, 1, 15, 9, 1] Best cost: 7205.840 | Path: [1, 3, 19, 17, 14, 15, 1, 7, 11, 4, 10, 1, 20, 6, 23, 21, 0, 1, 8, 18, 22, 5, 1, 13, 9, 1] Generation: #5 Best cost: 6938.676 | Path: [1, 21, 17, 14, 23, 1, 11, 7, 13, 20, 1, 0, 3, 19, 6, 15, 9, 1, 8, 18, 10, 22, 5, 1, 4, 1] OPTIMIZING each tour... Current: [[1, 21, 17, 14, 23, 1], [1, 11, 7, 13, 20, 1], [1, 0, 3, 19, 6, 15, 9, 1], [1, 8, 18, 10, 22, 5, 1], [1, 4, 1]] [1] Cost: 1860.008 to 1751.636 | Optimized: [1, 17, 14, 23, 21, 1] [2] Cost: 1216.319 to 1187.501 | Optimized: [1, 20, 13, 11, 7, 1] [3] Cost: 1677.723 to 1657.966 | Optimized: [1, 9, 15, 6, 19, 3, 0, 1] [4] Cost: 1618.666 to 1587.416 | Optimized: [1, 5, 22, 10, 8, 18, 1] ACO RESULTS [1/285 vol./1751.636 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [2/300 vol./1187.501 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/290 vol./1657.966 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Mainz Hbf -> Frankfurt Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/300 vol./1587.416 km] Berlin Hbf -> Aachen Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [5/100 vol./ 565.960 km] Berlin Hbf -> Hannover Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6750.479 km.