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: 22 customers
- Kassel-Wilhelmshöhe (40 vol.)
- Düsseldorf Hbf (85 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (50 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (60 vol.)
- Hamburg Hbf (50 vol.)
- München Hbf (45 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (85 vol.)
- Dortmund Hbf (30 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (70 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (65 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1569.512 km
LOAD: 275 vol.
- Mannheim Hbf | 90 vol.
- Karlsruhe Hbf | 70 vol.
- Saarbrücken Hbf | 20 vol.
- Mainz Hbf | 65 vol.
- Frankfurt Hbf | 30 vol.
Tour 2
COST: 1187.501 km
LOAD: 280 vol.
- Würzburg Hbf | 95 vol.
- Nürnberg Hbf | 40 vol.
- Leipzig Hbf | 85 vol.
- Dresden Hbf | 60 vol.
Tour 3
COST: 1283.046 km
LOAD: 275 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Dortmund Hbf | 30 vol.
- Düsseldorf Hbf | 85 vol.
- Köln Hbf | 35 vol.
- Osnabrück Hbf | 85 vol.
Tour 4
COST: 972.057 km
LOAD: 285 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 95 vol.
Tour 5
COST: 1827.547 km
LOAD: 240 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 30 vol.
- Freiburg Hbf | 85 vol.
LOAD: 275 vol.
- Mannheim Hbf | 90 vol.
- Karlsruhe Hbf | 70 vol.
- Saarbrücken Hbf | 20 vol.
- Mainz Hbf | 65 vol.
- Frankfurt Hbf | 30 vol.
LOAD: 280 vol.
- Würzburg Hbf | 95 vol.
- Nürnberg Hbf | 40 vol.
- Leipzig Hbf | 85 vol.
- Dresden Hbf | 60 vol.
LOAD: 275 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Dortmund Hbf | 30 vol.
- Düsseldorf Hbf | 85 vol.
- Köln Hbf | 35 vol.
- Osnabrück Hbf | 85 vol.
LOAD: 285 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 95 vol.
LOAD: 240 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 30 vol.
- Freiburg Hbf | 85 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: 1355 vol. | Vehicle capacity: 300 vol. Loads: [40, 0, 85, 30, 50, 0, 30, 60, 50, 45, 90, 85, 30, 40, 70, 80, 35, 90, 95, 65, 95, 20, 85, 85] ITERATION Generation: #1 Best cost: 7852.990 | Path: [1, 0, 12, 2, 16, 19, 3, 1, 7, 11, 20, 13, 21, 1, 8, 18, 10, 4, 1, 22, 17, 14, 6, 1, 15, 9, 23, 1] Best cost: 7692.223 | Path: [1, 2, 16, 12, 22, 4, 1, 11, 7, 13, 20, 21, 1, 8, 18, 10, 0, 1, 3, 19, 17, 14, 6, 1, 15, 9, 23, 1] Best cost: 7652.325 | Path: [1, 3, 19, 17, 14, 6, 1, 11, 7, 8, 18, 1, 4, 22, 10, 12, 16, 1, 0, 20, 13, 9, 15, 1, 2, 21, 23, 1] Best cost: 7533.924 | Path: [1, 6, 14, 17, 3, 19, 1, 11, 7, 13, 20, 21, 1, 4, 8, 18, 10, 1, 12, 2, 16, 22, 0, 1, 9, 15, 23, 1] Best cost: 7517.668 | Path: [1, 7, 11, 0, 4, 8, 1, 18, 10, 22, 12, 1, 20, 13, 9, 15, 6, 1, 16, 2, 19, 3, 21, 1, 17, 14, 23, 1] Best cost: 7462.352 | Path: [1, 9, 15, 6, 14, 19, 1, 7, 11, 20, 3, 21, 1, 18, 8, 10, 4, 1, 13, 17, 23, 16, 12, 1, 0, 22, 2, 1] Best cost: 7418.622 | Path: [1, 12, 2, 16, 19, 3, 21, 6, 1, 7, 11, 4, 10, 1, 8, 18, 22, 0, 1, 13, 20, 9, 15, 1, 17, 14, 23, 1] Best cost: 7409.016 | Path: [1, 8, 18, 10, 4, 1, 11, 7, 13, 20, 21, 1, 22, 12, 2, 16, 19, 1, 0, 3, 17, 14, 6, 1, 9, 15, 23, 1] Best cost: 7195.400 | Path: [1, 9, 15, 6, 14, 21, 3, 1, 4, 10, 8, 18, 1, 11, 7, 13, 20, 1, 12, 2, 16, 19, 0, 1, 22, 17, 23, 1] Best cost: 7180.877 | Path: [1, 23, 14, 17, 3, 21, 1, 11, 7, 13, 20, 1, 4, 10, 8, 18, 1, 0, 22, 12, 2, 16, 1, 19, 6, 15, 9, 1] Best cost: 7114.840 | Path: [1, 6, 14, 17, 19, 3, 1, 7, 11, 0, 12, 2, 1, 4, 10, 8, 18, 1, 22, 16, 21, 23, 13, 1, 20, 15, 9, 1] Best cost: 7067.795 | Path: [1, 14, 17, 3, 19, 21, 1, 11, 7, 13, 20, 1, 8, 18, 10, 4, 1, 22, 12, 2, 16, 0, 1, 9, 15, 6, 23, 1] Best cost: 7030.521 | Path: [1, 21, 19, 3, 17, 14, 1, 11, 7, 13, 20, 1, 4, 10, 8, 18, 1, 0, 12, 2, 16, 22, 1, 9, 15, 6, 23, 1] Best cost: 6989.238 | Path: [1, 21, 14, 17, 19, 3, 1, 11, 7, 13, 20, 1, 4, 10, 8, 18, 1, 12, 2, 16, 22, 0, 1, 9, 15, 6, 23, 1] Generation: #4 Best cost: 6953.844 | Path: [1, 21, 14, 17, 3, 19, 1, 11, 7, 13, 20, 1, 8, 18, 10, 4, 1, 0, 12, 2, 16, 22, 1, 9, 15, 6, 23, 1] Generation: #5 Best cost: 6928.966 | Path: [1, 21, 14, 17, 19, 3, 1, 11, 7, 13, 20, 1, 22, 12, 2, 16, 0, 1, 8, 18, 10, 4, 1, 9, 15, 6, 23, 1] OPTIMIZING each tour... Current: [[1, 21, 14, 17, 19, 3, 1], [1, 11, 7, 13, 20, 1], [1, 22, 12, 2, 16, 0, 1], [1, 8, 18, 10, 4, 1], [1, 9, 15, 6, 23, 1]] [1] Cost: 1604.657 to 1569.512 | Optimized: [1, 17, 14, 21, 19, 3, 1] [2] Cost: 1216.319 to 1187.501 | Optimized: [1, 20, 13, 11, 7, 1] [3] Cost: 1288.365 to 1283.046 | Optimized: [1, 0, 12, 2, 16, 22, 1] [4] Cost: 992.078 to 972.057 | Optimized: [1, 4, 10, 8, 18, 1] ACO RESULTS [1/275 vol./1569.512 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/280 vol./1187.501 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/275 vol./1283.046 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Osnabrück Hbf --> Berlin Hbf [4/285 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [5/240 vol./1827.547 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6839.663 km.