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 (95 vol.)
- Düsseldorf Hbf (70 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (90 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (25 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (85 vol.)
- Leipzig Hbf (45 vol.)
- Dortmund Hbf (100 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (20 vol.)
- Ulm Hbf (90 vol.)
- Köln Hbf (50 vol.)
- Mannheim Hbf (95 vol.)
- Kiel Hbf (100 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (95 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1806.862 km
LOAD: 290 vol.
- Frankfurt Hbf | 70 vol.
- Mannheim Hbf | 95 vol.
- Karlsruhe Hbf | 20 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 30 vol.
- Würzburg Hbf | 40 vol.
Tour 2
COST: 1351.104 km
LOAD: 295 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 45 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 95 vol.
Tour 3
COST: 972.057 km
LOAD: 255 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 25 vol.
- Kiel Hbf | 100 vol.
Tour 4
COST: 1156.449 km
LOAD: 265 vol.
- Dortmund Hbf | 100 vol.
- Düsseldorf Hbf | 70 vol.
- Osnabrück Hbf | 95 vol.
Tour 5
COST: 1342.718 km
LOAD: 245 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Aachen Hbf | 100 vol.
- Köln Hbf | 50 vol.
Tour 6
COST: 1341.186 km
LOAD: 180 vol.
- Ulm Hbf | 90 vol.
- Stuttgart Hbf | 90 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 70 vol.
- Mannheim Hbf | 95 vol.
- Karlsruhe Hbf | 20 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 30 vol.
- Würzburg Hbf | 40 vol.
LOAD: 295 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 45 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 95 vol.
LOAD: 255 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 25 vol.
- Kiel Hbf | 100 vol.
LOAD: 265 vol.
- Dortmund Hbf | 100 vol.
- Düsseldorf Hbf | 70 vol.
- Osnabrück Hbf | 95 vol.
LOAD: 245 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Aachen Hbf | 100 vol.
- Köln Hbf | 50 vol.
LOAD: 180 vol.
- Ulm Hbf | 90 vol.
- Stuttgart Hbf | 90 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: 1530 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 70, 70, 45, 100, 90, 95, 25, 95, 85, 45, 100, 60, 20, 90, 50, 95, 100, 0, 40, 30, 95, 35] ITERATION Generation: #1 Best cost: 8958.467 | Path: [1, 0, 22, 10, 8, 1, 11, 7, 13, 20, 14, 23, 1, 4, 12, 2, 16, 21, 1, 18, 5, 3, 1, 9, 15, 6, 1, 17, 1] Best cost: 8566.967 | Path: [1, 3, 17, 14, 6, 8, 1, 11, 7, 0, 4, 1, 22, 10, 18, 1, 13, 20, 15, 9, 1, 12, 2, 16, 21, 23, 1, 5, 1] Best cost: 8512.687 | Path: [1, 18, 8, 10, 4, 11, 1, 7, 0, 12, 1, 22, 2, 16, 3, 1, 13, 20, 6, 14, 21, 23, 1, 9, 15, 17, 1, 5, 1] Best cost: 8427.474 | Path: [1, 20, 13, 9, 15, 1, 11, 7, 3, 21, 14, 23, 1, 4, 10, 8, 18, 1, 0, 22, 12, 1, 16, 2, 5, 1, 17, 6, 1] Best cost: 8294.140 | Path: [1, 6, 14, 17, 3, 8, 1, 11, 7, 0, 4, 1, 18, 10, 22, 1, 13, 20, 15, 9, 1, 2, 16, 5, 21, 23, 1, 12, 1] Best cost: 8204.349 | Path: [1, 8, 18, 10, 4, 11, 1, 7, 20, 3, 17, 1, 15, 6, 14, 21, 23, 1, 22, 12, 2, 1, 0, 16, 5, 1, 13, 9, 1] Generation: #2 Best cost: 8039.538 | Path: [1, 20, 3, 17, 14, 23, 21, 1, 11, 7, 13, 9, 1, 8, 18, 10, 4, 1, 22, 12, 2, 1, 0, 16, 5, 1, 6, 15, 1] Best cost: 8027.227 | Path: [1, 21, 23, 14, 17, 3, 20, 1, 11, 7, 13, 9, 1, 4, 10, 8, 18, 1, 0, 12, 2, 1, 22, 16, 5, 1, 15, 6, 1] Best cost: 8022.131 | Path: [1, 20, 3, 17, 14, 23, 21, 1, 11, 7, 13, 9, 1, 4, 10, 8, 18, 1, 0, 12, 2, 1, 22, 16, 5, 1, 6, 15, 1] Generation: #4 Best cost: 8017.965 | Path: [1, 20, 3, 17, 14, 23, 21, 1, 11, 7, 13, 9, 1, 4, 10, 8, 18, 1, 22, 12, 2, 1, 0, 16, 5, 1, 15, 6, 1] OPTIMIZING each tour... Current: [[1, 20, 3, 17, 14, 23, 21, 1], [1, 11, 7, 13, 9, 1], [1, 4, 10, 8, 18, 1], [1, 22, 12, 2, 1], [1, 0, 16, 5, 1], [1, 15, 6, 1]] [1] Cost: 1813.843 to 1806.862 | Optimized: [1, 3, 17, 14, 23, 21, 20, 1] [2] Cost: 1377.326 to 1351.104 | Optimized: [1, 7, 11, 13, 9, 1] [4] Cost: 1170.293 to 1156.449 | Optimized: [1, 12, 2, 22, 1] [5] Cost: 1343.260 to 1342.718 | Optimized: [1, 0, 5, 16, 1] ACO RESULTS [1/290 vol./1806.862 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Würzburg Hbf --> Berlin Hbf [2/295 vol./1351.104 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf [3/255 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/265 vol./1156.449 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf --> Berlin Hbf [5/245 vol./1342.718 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Aachen Hbf -> Köln Hbf --> Berlin Hbf [6/180 vol./1341.186 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf --> Berlin Hbf OPTIMIZATION RESULT: 6 tours | 7970.376 km.