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: 15 customers
- Kassel-Wilhelmshöhe (90 vol.)
- Aachen Hbf (80 vol.)
- Dresden Hbf (55 vol.)
- Hamburg Hbf (85 vol.)
- Bremen Hbf (55 vol.)
- Dortmund Hbf (80 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (80 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (45 vol.)
- Saarbrücken Hbf (95 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1733.908 km
LOAD: 290 vol.
- Mainz Hbf | 75 vol.
- Mannheim Hbf | 90 vol.
- Freiburg Hbf | 70 vol.
- Dresden Hbf | 55 vol.
Tour 2
COST: 1295.458 km
LOAD: 300 vol.
- Dortmund Hbf | 80 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 80 vol.
Tour 3
COST: 1550.592 km
LOAD: 295 vol.
- Würzburg Hbf | 45 vol.
- Köln Hbf | 80 vol.
- Aachen Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 90 vol.
Tour 4
COST: 1642.003 km
LOAD: 285 vol.
- Saarbrücken Hbf | 95 vol.
- Karlsruhe Hbf | 95 vol.
- Ulm Hbf | 95 vol.
LOAD: 290 vol.
- Mainz Hbf | 75 vol.
- Mannheim Hbf | 90 vol.
- Freiburg Hbf | 70 vol.
- Dresden Hbf | 55 vol.
LOAD: 300 vol.
- Dortmund Hbf | 80 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 80 vol.
LOAD: 295 vol.
- Würzburg Hbf | 45 vol.
- Köln Hbf | 80 vol.
- Aachen Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 90 vol.
LOAD: 285 vol.
- Saarbrücken Hbf | 95 vol.
- Karlsruhe Hbf | 95 vol.
- Ulm Hbf | 95 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: 1170 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 0, 0, 0, 80, 0, 55, 85, 0, 55, 0, 80, 0, 95, 95, 80, 90, 80, 75, 45, 95, 0, 70] ITERATION Generation: #1 Best cost: 7246.738 | Path: [1, 0, 12, 16, 20, 1, 7, 18, 8, 10, 1, 15, 14, 17, 1, 19, 21, 23, 1, 5, 1] Best cost: 7240.557 | Path: [1, 7, 20, 19, 17, 1, 8, 18, 10, 12, 1, 0, 16, 5, 1, 15, 14, 23, 1, 21, 1] Best cost: 6838.390 | Path: [1, 10, 8, 18, 5, 1, 7, 0, 12, 19, 1, 20, 14, 17, 23, 1, 15, 21, 16, 1] Best cost: 6646.978 | Path: [1, 15, 14, 17, 1, 7, 0, 12, 19, 1, 8, 18, 10, 5, 1, 20, 16, 21, 23, 1] Best cost: 6341.120 | Path: [1, 18, 8, 10, 12, 1, 7, 0, 16, 19, 1, 20, 17, 14, 23, 1, 15, 21, 5, 1] Best cost: 6322.043 | Path: [1, 20, 14, 17, 23, 1, 7, 19, 16, 5, 1, 8, 18, 10, 12, 1, 0, 21, 15, 1] Best cost: 6294.974 | Path: [1, 17, 14, 23, 20, 1, 7, 0, 19, 16, 1, 8, 18, 10, 12, 1, 15, 21, 5, 1] Generation: #7 Best cost: 6291.038 | Path: [1, 7, 19, 17, 23, 1, 8, 18, 10, 12, 1, 0, 16, 5, 20, 1, 15, 14, 21, 1] OPTIMIZING each tour... Current: [[1, 7, 19, 17, 23, 1], [1, 8, 18, 10, 12, 1], [1, 0, 16, 5, 20, 1], [1, 15, 14, 21, 1]] [1] Cost: 1772.993 to 1733.908 | Optimized: [1, 19, 17, 23, 7, 1] [2] Cost: 1315.948 to 1295.458 | Optimized: [1, 12, 10, 8, 18, 1] [3] Cost: 1555.778 to 1550.592 | Optimized: [1, 20, 16, 5, 0, 1] [4] Cost: 1646.319 to 1642.003 | Optimized: [1, 21, 14, 15, 1] ACO RESULTS [1/290 vol./1733.908 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Freiburg Hbf -> Dresden Hbf --> Berlin Hbf [2/300 vol./1295.458 km] Berlin Hbf -> Dortmund Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/295 vol./1550.592 km] Berlin Hbf -> Würzburg Hbf -> Köln Hbf -> Aachen Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/285 vol./1642.003 km] Berlin Hbf -> Saarbrücken Hbf -> Karlsruhe Hbf -> Ulm Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6221.961 km.