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 (45 vol.)
- Frankfurt Hbf (100 vol.)
- Hannover Hbf (100 vol.)
- Stuttgart Hbf (60 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (35 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (25 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (50 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (35 vol.)
- Saarbrücken Hbf (45 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1409.247 km
LOAD: 285 vol.
- Frankfurt Hbf | 100 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 50 vol.
- Karlsruhe Hbf | 80 vol.
- Würzburg Hbf | 35 vol.
Tour 2
COST: 2111.896 km
LOAD: 300 vol.
- Leipzig Hbf | 40 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 35 vol.
- Ulm Hbf | 25 vol.
- Stuttgart Hbf | 60 vol.
- Freiburg Hbf | 50 vol.
- Saarbrücken Hbf | 45 vol.
- Dortmund Hbf | 20 vol.
Tour 3
COST: 1107.833 km
LOAD: 285 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 35 vol.
Tour 4
COST: 1208.478 km
LOAD: 205 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Köln Hbf | 60 vol.
- Hannover Hbf | 100 vol.
LOAD: 285 vol.
- Frankfurt Hbf | 100 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 50 vol.
- Karlsruhe Hbf | 80 vol.
- Würzburg Hbf | 35 vol.
LOAD: 300 vol.
- Leipzig Hbf | 40 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 35 vol.
- Ulm Hbf | 25 vol.
- Stuttgart Hbf | 60 vol.
- Freiburg Hbf | 50 vol.
- Saarbrücken Hbf | 45 vol.
- Dortmund Hbf | 20 vol.
LOAD: 285 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 35 vol.
LOAD: 205 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Köln Hbf | 60 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: 1075 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 0, 100, 100, 0, 60, 0, 100, 35, 100, 40, 20, 25, 80, 25, 60, 50, 35, 20, 35, 45, 50, 50] ITERATION Generation: #1 Best cost: 6667.295 | Path: [1, 0, 12, 16, 19, 3, 17, 1, 11, 13, 20, 6, 15, 14, 9, 1, 4, 8, 18, 22, 1, 10, 21, 23, 1] Best cost: 6608.337 | Path: [1, 4, 10, 8, 1, 11, 0, 12, 22, 16, 19, 17, 1, 18, 20, 13, 9, 15, 6, 14, 1, 3, 21, 23, 1] Best cost: 6320.739 | Path: [1, 8, 18, 10, 22, 1, 11, 13, 20, 3, 19, 17, 15, 1, 4, 0, 12, 16, 21, 1, 9, 6, 14, 23, 1] Best cost: 6306.140 | Path: [1, 18, 8, 10, 22, 1, 11, 0, 4, 12, 16, 19, 1, 20, 3, 17, 14, 15, 1, 13, 9, 6, 23, 21, 1] Best cost: 6211.507 | Path: [1, 8, 18, 10, 22, 1, 11, 0, 20, 3, 19, 17, 1, 4, 12, 16, 21, 6, 1, 13, 9, 15, 14, 23, 1] Best cost: 6174.405 | Path: [1, 11, 0, 20, 13, 9, 15, 6, 19, 1, 8, 18, 10, 22, 1, 4, 12, 16, 3, 1, 17, 14, 23, 21, 1] Best cost: 6143.461 | Path: [1, 18, 8, 10, 22, 1, 11, 4, 0, 3, 1, 20, 19, 17, 14, 6, 15, 13, 1, 12, 16, 21, 23, 9, 1] Best cost: 5985.431 | Path: [1, 20, 3, 19, 17, 14, 1, 11, 13, 9, 15, 6, 23, 21, 12, 1, 8, 18, 10, 22, 1, 4, 0, 16, 1] OPTIMIZING each tour... Current: [[1, 20, 3, 19, 17, 14, 1], [1, 11, 13, 9, 15, 6, 23, 21, 12, 1], [1, 8, 18, 10, 22, 1], [1, 4, 0, 16, 1]] [1] Cost: 1465.825 to 1409.247 | Optimized: [1, 3, 19, 17, 14, 20, 1] [3] Cost: 1132.488 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] [4] Cost: 1275.222 to 1208.478 | Optimized: [1, 0, 16, 4, 1] ACO RESULTS [1/285 vol./1409.247 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Würzburg Hbf --> Berlin Hbf [2/300 vol./2111.896 km] Berlin Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Dortmund Hbf --> Berlin Hbf [3/285 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/205 vol./1208.478 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Köln Hbf -> Hannover Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5837.454 km.