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 (70 vol.)
- Düsseldorf Hbf (30 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (45 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (70 vol.)
- Ulm Hbf (80 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (45 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (60 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1329.758 km
LOAD: 295 vol.
- Frankfurt Hbf | 90 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 75 vol.
- Würzburg Hbf | 85 vol.
Tour 2
COST: 1520.359 km
LOAD: 300 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 80 vol.
- Nürnberg Hbf | 70 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 85 vol.
Tour 3
COST: 1134.987 km
LOAD: 280 vol.
- Hamburg Hbf | 90 vol.
- Bremen Hbf | 75 vol.
- Dortmund Hbf | 20 vol.
- Hannover Hbf | 95 vol.
Tour 4
COST: 1997.955 km
LOAD: 280 vol.
- Stuttgart Hbf | 45 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 60 vol.
- Aachen Hbf | 30 vol.
- Düsseldorf Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 70 vol.
Tour 5
COST: 701.943 km
LOAD: 80 vol.
- Kiel Hbf | 80 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 90 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 75 vol.
- Würzburg Hbf | 85 vol.
LOAD: 300 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 80 vol.
- Nürnberg Hbf | 70 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 85 vol.
LOAD: 280 vol.
- Hamburg Hbf | 90 vol.
- Bremen Hbf | 75 vol.
- Dortmund Hbf | 20 vol.
- Hannover Hbf | 95 vol.
LOAD: 280 vol.
- Stuttgart Hbf | 45 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 60 vol.
- Aachen Hbf | 30 vol.
- Düsseldorf Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 70 vol.
LOAD: 80 vol.
- Kiel 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: 1235 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 30, 90, 95, 30, 45, 85, 90, 25, 75, 40, 20, 70, 0, 80, 0, 75, 80, 45, 85, 60, 0, 45] ITERATION Generation: #1 Best cost: 7765.341 | Path: [1, 0, 12, 2, 5, 17, 19, 9, 1, 11, 7, 13, 20, 1, 4, 8, 18, 1, 10, 3, 15, 6, 1, 21, 23, 1] Best cost: 7725.051 | Path: [1, 4, 10, 8, 11, 1, 7, 13, 20, 19, 1, 0, 2, 12, 3, 17, 1, 18, 5, 21, 23, 6, 9, 1, 15, 1] Best cost: 7350.813 | Path: [1, 7, 11, 0, 4, 1, 18, 8, 10, 2, 12, 1, 13, 20, 3, 19, 1, 9, 15, 6, 23, 17, 5, 1, 21, 1] Best cost: 7314.305 | Path: [1, 17, 19, 3, 20, 1, 7, 11, 4, 10, 1, 8, 18, 2, 12, 5, 6, 1, 13, 9, 15, 23, 21, 1, 0, 1] Best cost: 7263.899 | Path: [1, 17, 19, 3, 20, 1, 11, 7, 13, 9, 15, 1, 4, 8, 18, 2, 1, 0, 12, 5, 21, 23, 6, 1, 10, 1] Best cost: 7097.016 | Path: [1, 15, 6, 17, 19, 2, 12, 1, 7, 11, 13, 20, 1, 8, 10, 4, 5, 1, 0, 3, 21, 23, 9, 1, 18, 1] Best cost: 7091.201 | Path: [1, 17, 19, 3, 20, 1, 11, 7, 13, 9, 15, 1, 8, 18, 4, 12, 1, 10, 2, 5, 21, 23, 6, 1, 0, 1] Generation: #2 Best cost: 7016.214 | Path: [1, 17, 19, 3, 20, 1, 11, 7, 13, 9, 15, 1, 8, 18, 4, 12, 1, 0, 2, 5, 21, 23, 6, 1, 10, 1] Generation: #5 Best cost: 6966.015 | Path: [1, 17, 19, 3, 20, 1, 11, 7, 13, 9, 15, 1, 4, 10, 8, 12, 1, 0, 2, 5, 21, 23, 6, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 17, 19, 3, 20, 1], [1, 11, 7, 13, 9, 15, 1], [1, 4, 10, 8, 12, 1], [1, 0, 2, 5, 21, 23, 6, 1], [1, 18, 1]] [1] Cost: 1343.081 to 1329.758 | Optimized: [1, 3, 19, 17, 20, 1] [2] Cost: 1553.708 to 1520.359 | Optimized: [1, 9, 15, 13, 11, 7, 1] [3] Cost: 1366.069 to 1134.987 | Optimized: [1, 8, 10, 12, 4, 1] [4] Cost: 2001.214 to 1997.955 | Optimized: [1, 6, 23, 21, 5, 2, 0, 1] ACO RESULTS [1/295 vol./1329.758 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Würzburg Hbf --> Berlin Hbf [2/300 vol./1520.359 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/280 vol./1134.987 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Dortmund Hbf -> Hannover Hbf --> Berlin Hbf [4/280 vol./1997.955 km] Berlin Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [5/ 80 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6685.002 km.