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: 16 customers
- Kassel-Wilhelmshöhe (100 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (85 vol.)
- Stuttgart Hbf (70 vol.)
- Hamburg Hbf (50 vol.)
- Bremen Hbf (50 vol.)
- Leipzig Hbf (70 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (80 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (30 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (100 vol.)
Tour 1
COST: 1240.678 km
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Frankfurt Hbf | 80 vol.
- Mainz Hbf | 30 vol.
- Leipzig Hbf | 70 vol.
Tour 2
COST: 1107.833 km
LOAD: 285 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 50 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 95 vol.
Tour 3
COST: 1909.389 km
LOAD: 270 vol.
- Freiburg Hbf | 100 vol.
- Saarbrücken Hbf | 30 vol.
- Aachen Hbf | 85 vol.
- Hannover Hbf | 55 vol.
Tour 4
COST: 1480.9 km
LOAD: 280 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 45 vol.
- Stuttgart Hbf | 70 vol.
- Ulm Hbf | 80 vol.
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Frankfurt Hbf | 80 vol.
- Mainz Hbf | 30 vol.
- Leipzig Hbf | 70 vol.
LOAD: 285 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 50 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 95 vol.
LOAD: 270 vol.
- Freiburg Hbf | 100 vol.
- Saarbrücken Hbf | 30 vol.
- Aachen Hbf | 85 vol.
- Hannover Hbf | 55 vol.
LOAD: 280 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 45 vol.
- Stuttgart Hbf | 70 vol.
- Ulm 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: 1115 vol. | Vehicle capacity: 300 vol. Loads: [100, 0, 0, 80, 55, 85, 70, 0, 50, 0, 50, 70, 0, 0, 45, 80, 0, 85, 95, 30, 0, 30, 90, 100] ITERATION Generation: #1 Best cost: 6525.053 | Path: [1, 0, 22, 10, 8, 1, 11, 4, 18, 3, 1, 17, 14, 6, 15, 1, 5, 21, 19, 23, 1] Best cost: 6345.322 | Path: [1, 4, 10, 22, 0, 1, 11, 3, 19, 17, 21, 1, 18, 8, 5, 14, 1, 15, 6, 23, 1] Best cost: 6334.284 | Path: [1, 10, 4, 22, 0, 1, 11, 15, 6, 14, 19, 1, 8, 18, 5, 21, 1, 3, 17, 23, 1] Best cost: 6267.456 | Path: [1, 18, 8, 10, 22, 1, 11, 4, 0, 19, 21, 1, 3, 17, 14, 6, 1, 15, 23, 5, 1] Best cost: 6123.887 | Path: [1, 15, 6, 14, 17, 1, 11, 3, 19, 21, 5, 1, 4, 8, 18, 10, 1, 22, 0, 23, 1] Best cost: 6048.265 | Path: [1, 22, 10, 8, 18, 1, 11, 0, 3, 19, 1, 4, 5, 17, 14, 21, 1, 6, 15, 23, 1] Best cost: 5846.759 | Path: [1, 18, 8, 10, 22, 1, 11, 0, 3, 19, 1, 4, 5, 21, 14, 17, 1, 15, 6, 23, 1] Generation: #2 Best cost: 5832.933 | Path: [1, 22, 10, 8, 18, 1, 11, 0, 3, 19, 1, 4, 5, 21, 14, 17, 1, 15, 6, 23, 1] Generation: #10 Best cost: 5786.377 | Path: [1, 11, 0, 3, 19, 1, 18, 8, 10, 22, 1, 4, 5, 21, 23, 1, 15, 6, 14, 17, 1] OPTIMIZING each tour... Current: [[1, 11, 0, 3, 19, 1], [1, 18, 8, 10, 22, 1], [1, 4, 5, 21, 23, 1], [1, 15, 6, 14, 17, 1]] [1] Cost: 1269.930 to 1240.678 | Optimized: [1, 0, 3, 19, 11, 1] [2] Cost: 1121.659 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] [3] Cost: 1911.458 to 1909.389 | Optimized: [1, 23, 21, 5, 4, 1] [4] Cost: 1483.330 to 1480.900 | Optimized: [1, 17, 14, 6, 15, 1] ACO RESULTS [1/280 vol./1240.678 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Leipzig Hbf --> Berlin Hbf [2/285 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/270 vol./1909.389 km] Berlin Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Hannover Hbf --> Berlin Hbf [4/280 vol./1480.900 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5738.800 km.