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: 21 customers
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (75 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (95 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (85 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (40 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (55 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (20 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (55 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1082.275 km
LOAD: 285 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 50 vol.
- Hannover Hbf | 55 vol.
- Bremen Hbf | 85 vol.
Tour 2
COST: 1416.311 km
LOAD: 285 vol.
- Dortmund Hbf | 40 vol.
- Düsseldorf Hbf | 80 vol.
- Osnabrück Hbf | 55 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 25 vol.
Tour 3
COST: 1625.696 km
LOAD: 290 vol.
- Mainz Hbf | 55 vol.
- Saarbrücken Hbf | 70 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 70 vol.
Tour 4
COST: 1629.081 km
LOAD: 280 vol.
- Frankfurt Hbf | 75 vol.
- Mannheim Hbf | 70 vol.
- Karlsruhe Hbf | 95 vol.
- Freiburg Hbf | 20 vol.
- Würzburg Hbf | 20 vol.
Tour 5
COST: 1357.805 km
LOAD: 235 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 55 vol.
- Nürnberg Hbf | 100 vol.
LOAD: 285 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 50 vol.
- Hannover Hbf | 55 vol.
- Bremen Hbf | 85 vol.
LOAD: 285 vol.
- Dortmund Hbf | 40 vol.
- Düsseldorf Hbf | 80 vol.
- Osnabrück Hbf | 55 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 25 vol.
LOAD: 290 vol.
- Mainz Hbf | 55 vol.
- Saarbrücken Hbf | 70 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 70 vol.
LOAD: 280 vol.
- Frankfurt Hbf | 75 vol.
- Mannheim Hbf | 70 vol.
- Karlsruhe Hbf | 95 vol.
- Freiburg Hbf | 20 vol.
- Würzburg Hbf | 20 vol.
LOAD: 235 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 55 vol.
- Nürnberg 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: 1375 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 80, 75, 55, 95, 0, 95, 85, 80, 85, 50, 40, 100, 95, 55, 70, 70, 25, 55, 20, 70, 55, 20] ITERATION Generation: #1 Best cost: 8550.591 | Path: [1, 2, 16, 5, 12, 1, 11, 7, 13, 20, 23, 1, 8, 18, 4, 22, 3, 1, 10, 17, 14, 1, 15, 9, 19, 21, 1] Best cost: 8087.182 | Path: [1, 3, 19, 17, 14, 1, 11, 7, 13, 20, 23, 1, 4, 10, 8, 18, 12, 1, 22, 2, 16, 5, 1, 15, 9, 21, 1] Best cost: 7788.013 | Path: [1, 4, 10, 8, 18, 12, 1, 11, 7, 13, 20, 23, 1, 22, 2, 16, 5, 1, 9, 15, 14, 17, 1, 3, 19, 21, 1] Best cost: 7554.630 | Path: [1, 8, 18, 10, 4, 12, 1, 7, 11, 19, 3, 20, 1, 22, 16, 2, 5, 1, 13, 9, 15, 23, 1, 17, 14, 21, 1] Best cost: 7424.203 | Path: [1, 12, 2, 16, 5, 1, 7, 11, 13, 20, 23, 1, 8, 18, 10, 4, 1, 22, 19, 3, 17, 1, 9, 15, 14, 21, 1] Best cost: 7362.339 | Path: [1, 23, 14, 17, 3, 20, 1, 7, 11, 4, 10, 1, 8, 18, 22, 12, 2, 1, 16, 5, 19, 21, 1, 13, 15, 9, 1] Best cost: 7356.597 | Path: [1, 19, 3, 17, 14, 1, 11, 7, 4, 10, 1, 8, 18, 22, 12, 2, 1, 16, 5, 21, 23, 20, 1, 13, 9, 15, 1] Best cost: 7261.310 | Path: [1, 14, 17, 3, 19, 1, 7, 11, 4, 10, 1, 8, 18, 22, 12, 2, 1, 16, 5, 21, 23, 20, 1, 9, 15, 13, 1] Best cost: 7211.488 | Path: [1, 12, 2, 16, 5, 1, 7, 11, 10, 4, 1, 8, 18, 22, 3, 19, 1, 17, 14, 23, 21, 20, 1, 13, 9, 15, 1] Generation: #7 Best cost: 7154.873 | Path: [1, 7, 11, 4, 10, 1, 8, 18, 22, 12, 2, 1, 16, 5, 21, 19, 1, 3, 17, 14, 23, 20, 1, 9, 15, 13, 1] OPTIMIZING each tour... Current: [[1, 7, 11, 4, 10, 1], [1, 8, 18, 22, 12, 2, 1], [1, 16, 5, 21, 19, 1], [1, 3, 17, 14, 23, 20, 1], [1, 9, 15, 13, 1]] [2] Cost: 1455.024 to 1416.311 | Optimized: [1, 12, 2, 22, 8, 18, 1] [3] Cost: 1630.688 to 1625.696 | Optimized: [1, 19, 21, 5, 16, 1] ACO RESULTS [1/285 vol./1082.275 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf --> Berlin Hbf [2/285 vol./1416.311 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/290 vol./1625.696 km] Berlin Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf --> Berlin Hbf [4/280 vol./1629.081 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [5/235 vol./1357.805 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7111.168 km.