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: 19 customers
- Kassel-Wilhelmshöhe (45 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (80 vol.)
- Stuttgart Hbf (100 vol.)
- Dresden Hbf (85 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (50 vol.)
- Leipzig Hbf (85 vol.)
- Dortmund Hbf (20 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (80 vol.)
- Mannheim Hbf (55 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (60 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (85 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1047.518 km
LOAD: 295 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Hannover Hbf | 80 vol.
Tour 2
COST: 1415.647 km
LOAD: 285 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 95 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 50 vol.
- Kiel Hbf | 35 vol.
Tour 3
COST: 1608.84 km
LOAD: 290 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 100 vol.
- Mannheim Hbf | 55 vol.
- Würzburg Hbf | 30 vol.
Tour 4
COST: 1747.015 km
LOAD: 285 vol.
- Frankfurt Hbf | 80 vol.
- Mainz Hbf | 60 vol.
- Saarbrücken Hbf | 85 vol.
- Freiburg Hbf | 60 vol.
Tour 5
COST: 1143.25 km
LOAD: 80 vol.
- Köln Hbf | 80 vol.
LOAD: 295 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Hannover Hbf | 80 vol.
LOAD: 285 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 95 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 50 vol.
- Kiel Hbf | 35 vol.
LOAD: 290 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 100 vol.
- Mannheim Hbf | 55 vol.
- Würzburg Hbf | 30 vol.
LOAD: 285 vol.
- Frankfurt Hbf | 80 vol.
- Mainz Hbf | 60 vol.
- Saarbrücken Hbf | 85 vol.
- Freiburg Hbf | 60 vol.
LOAD: 80 vol.
- Köln Hbf | 80 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: 1235 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 95, 80, 80, 0, 100, 85, 0, 25, 50, 85, 20, 0, 0, 80, 80, 55, 35, 60, 30, 85, 85, 60] ITERATION Generation: #1 Best cost: 8368.318 | Path: [1, 0, 22, 10, 4, 12, 1, 11, 7, 20, 3, 1, 18, 16, 2, 19, 9, 1, 17, 6, 15, 23, 1, 21, 1] Best cost: 7996.306 | Path: [1, 2, 16, 12, 22, 1, 11, 7, 20, 3, 1, 4, 10, 18, 0, 19, 9, 1, 6, 17, 21, 23, 1, 15, 1] Best cost: 7914.161 | Path: [1, 4, 10, 22, 12, 0, 1, 11, 7, 20, 3, 1, 18, 2, 16, 19, 9, 1, 15, 6, 17, 23, 1, 21, 1] Best cost: 7774.826 | Path: [1, 6, 15, 9, 20, 19, 1, 11, 7, 0, 4, 1, 22, 12, 2, 16, 1, 18, 10, 3, 17, 23, 1, 21, 1] Best cost: 7644.418 | Path: [1, 9, 15, 6, 17, 20, 1, 7, 11, 0, 4, 1, 22, 10, 12, 2, 18, 1, 16, 19, 3, 23, 1, 21, 1] Best cost: 7644.013 | Path: [1, 10, 4, 22, 12, 0, 1, 11, 7, 15, 9, 1, 18, 16, 2, 19, 20, 1, 3, 17, 23, 21, 1, 6, 1] Best cost: 7549.350 | Path: [1, 15, 6, 17, 19, 1, 11, 7, 0, 12, 10, 1, 4, 22, 2, 18, 1, 20, 3, 21, 23, 9, 1, 16, 1] Best cost: 7448.503 | Path: [1, 11, 7, 4, 10, 1, 18, 22, 0, 12, 2, 1, 20, 3, 19, 17, 23, 1, 9, 15, 6, 21, 1, 16, 1] Best cost: 7400.357 | Path: [1, 23, 6, 15, 9, 20, 1, 7, 11, 10, 4, 1, 18, 22, 12, 16, 3, 1, 0, 19, 17, 21, 1, 2, 1] Best cost: 7219.585 | Path: [1, 18, 10, 22, 12, 2, 1, 7, 11, 4, 0, 1, 20, 3, 19, 17, 23, 1, 9, 15, 6, 21, 1, 16, 1] Best cost: 7167.092 | Path: [1, 9, 15, 6, 17, 20, 1, 11, 7, 4, 10, 1, 18, 22, 12, 2, 0, 1, 3, 19, 21, 23, 1, 16, 1] Best cost: 7146.876 | Path: [1, 3, 19, 17, 21, 12, 1, 11, 7, 4, 10, 1, 18, 22, 2, 16, 1, 20, 6, 15, 9, 23, 1, 0, 1] Best cost: 7118.614 | Path: [1, 7, 11, 0, 4, 1, 18, 10, 22, 12, 2, 1, 20, 3, 19, 17, 23, 1, 9, 15, 6, 21, 1, 16, 1] Best cost: 7077.302 | Path: [1, 9, 15, 6, 17, 20, 1, 11, 7, 0, 4, 1, 18, 10, 22, 12, 2, 1, 3, 19, 21, 23, 1, 16, 1] Generation: #2 Best cost: 7047.680 | Path: [1, 3, 19, 17, 21, 12, 1, 7, 11, 4, 10, 1, 18, 22, 2, 16, 1, 20, 6, 15, 9, 23, 1, 0, 1] Best cost: 7042.301 | Path: [1, 7, 11, 0, 4, 1, 18, 10, 22, 12, 2, 1, 9, 15, 6, 17, 20, 1, 19, 3, 21, 23, 1, 16, 1] OPTIMIZING each tour... Current: [[1, 7, 11, 0, 4, 1], [1, 18, 10, 22, 12, 2, 1], [1, 9, 15, 6, 17, 20, 1], [1, 19, 3, 21, 23, 1], [1, 16, 1]] [2] Cost: 1435.667 to 1415.647 | Optimized: [1, 12, 2, 22, 10, 18, 1] [4] Cost: 1807.026 to 1747.015 | Optimized: [1, 3, 19, 21, 23, 1] ACO RESULTS [1/295 vol./1047.518 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf --> Berlin Hbf [2/285 vol./1415.647 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [3/290 vol./1608.840 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Würzburg Hbf --> Berlin Hbf [4/285 vol./1747.015 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf --> Berlin Hbf [5/ 80 vol./1143.250 km] Berlin Hbf -> Köln Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6962.270 km.