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.)
- Düsseldorf Hbf (75 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (95 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (35 vol.)
- Bremen Hbf (70 vol.)
- Leipzig Hbf (30 vol.)
- Dortmund Hbf (100 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (50 vol.)
- Köln Hbf (45 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (25 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1409.247 km
LOAD: 295 vol.
- Frankfurt Hbf | 60 vol.
- Mainz Hbf | 25 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 40 vol.
- Würzburg Hbf | 85 vol.
Tour 2
COST: 1271.626 km
LOAD: 295 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Hannover Hbf | 65 vol.
- Bremen Hbf | 70 vol.
Tour 3
COST: 1416.311 km
LOAD: 300 vol.
- Dortmund Hbf | 100 vol.
- Düsseldorf Hbf | 75 vol.
- Osnabrück Hbf | 20 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 70 vol.
Tour 4
COST: 2017.862 km
LOAD: 300 vol.
- Ulm Hbf | 50 vol.
- Freiburg Hbf | 85 vol.
- Saarbrücken Hbf | 25 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 45 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 60 vol.
- Mainz Hbf | 25 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 40 vol.
- Würzburg Hbf | 85 vol.
LOAD: 295 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Hannover Hbf | 65 vol.
- Bremen Hbf | 70 vol.
LOAD: 300 vol.
- Dortmund Hbf | 100 vol.
- Düsseldorf Hbf | 75 vol.
- Osnabrück Hbf | 20 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 70 vol.
LOAD: 300 vol.
- Ulm Hbf | 50 vol.
- Freiburg Hbf | 85 vol.
- Saarbrücken Hbf | 25 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 45 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: 1190 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 75, 60, 65, 95, 0, 85, 35, 0, 70, 30, 100, 0, 40, 50, 45, 85, 70, 25, 85, 25, 20, 85] ITERATION Generation: #1 Best cost: 9055.752 | Path: [1, 0, 22, 10, 4, 8, 11, 19, 1, 7, 20, 3, 16, 21, 1, 18, 12, 2, 14, 1, 17, 23, 15, 1, 5, 1] Best cost: 7995.352 | Path: [1, 2, 16, 5, 3, 19, 1, 7, 11, 0, 4, 10, 1, 8, 18, 22, 12, 14, 21, 1, 20, 15, 17, 1, 23, 1] Best cost: 7381.944 | Path: [1, 4, 10, 22, 12, 16, 1, 11, 7, 0, 3, 19, 21, 1, 8, 18, 2, 5, 1, 17, 14, 23, 15, 1, 20, 1] Best cost: 7313.600 | Path: [1, 12, 22, 4, 10, 8, 1, 11, 7, 20, 3, 19, 1, 18, 2, 16, 5, 1, 0, 17, 14, 23, 21, 1, 15, 1] Best cost: 6575.119 | Path: [1, 3, 19, 17, 14, 23, 1, 11, 7, 0, 4, 10, 1, 8, 18, 22, 12, 2, 1, 5, 16, 21, 20, 15, 1] Best cost: 6293.519 | Path: [1, 7, 11, 0, 4, 10, 1, 8, 18, 22, 12, 2, 1, 17, 14, 23, 19, 3, 1, 20, 15, 21, 5, 16, 1] Best cost: 6271.943 | Path: [1, 14, 17, 19, 3, 20, 1, 7, 11, 0, 4, 10, 1, 8, 18, 22, 12, 2, 1, 15, 23, 21, 16, 5, 1] OPTIMIZING each tour... Current: [[1, 14, 17, 19, 3, 20, 1], [1, 7, 11, 0, 4, 10, 1], [1, 8, 18, 22, 12, 2, 1], [1, 15, 23, 21, 16, 5, 1]] [1] Cost: 1467.767 to 1409.247 | Optimized: [1, 3, 19, 17, 14, 20, 1] [3] Cost: 1455.024 to 1416.311 | Optimized: [1, 12, 2, 22, 8, 18, 1] [4] Cost: 2077.526 to 2017.862 | Optimized: [1, 15, 23, 21, 5, 16, 1] ACO RESULTS [1/295 vol./1409.247 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Würzburg Hbf --> Berlin Hbf [2/295 vol./1271.626 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf --> Berlin Hbf [3/300 vol./1416.311 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/300 vol./2017.862 km] Berlin Hbf -> Ulm Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6115.046 km.