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: 22 customers
- Düsseldorf Hbf (50 vol.)
- Frankfurt Hbf (65 vol.)
- Hannover Hbf (35 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (80 vol.)
- Dresden Hbf (40 vol.)
- Hamburg Hbf (25 vol.)
- München Hbf (30 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (75 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (70 vol.)
- Ulm Hbf (55 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (45 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (95 vol.)
- Osnabrück Hbf (30 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1363.131 km
LOAD: 300 vol.
- Dortmund Hbf | 75 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 65 vol.
- Aachen Hbf | 45 vol.
- Osnabrück Hbf | 30 vol.
- Hannover Hbf | 35 vol.
Tour 2
COST: 1371.845 km
LOAD: 295 vol.
- Frankfurt Hbf | 65 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 65 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 40 vol.
Tour 3
COST: 1891.56 km
LOAD: 300 vol.
- Kiel Hbf | 45 vol.
- Hamburg Hbf | 25 vol.
- Bremen Hbf | 45 vol.
- Saarbrücken Hbf | 95 vol.
- Mannheim Hbf | 90 vol.
Tour 4
COST: 1767.185 km
LOAD: 295 vol.
- Mainz Hbf | 25 vol.
- Karlsruhe Hbf | 70 vol.
- Freiburg Hbf | 65 vol.
- Stuttgart Hbf | 80 vol.
- Ulm Hbf | 55 vol.
Tour 5
COST: 1170.132 km
LOAD: 30 vol.
- München Hbf | 30 vol.
LOAD: 300 vol.
- Dortmund Hbf | 75 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 65 vol.
- Aachen Hbf | 45 vol.
- Osnabrück Hbf | 30 vol.
- Hannover Hbf | 35 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 65 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 65 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 40 vol.
LOAD: 300 vol.
- Kiel Hbf | 45 vol.
- Hamburg Hbf | 25 vol.
- Bremen Hbf | 45 vol.
- Saarbrücken Hbf | 95 vol.
- Mannheim Hbf | 90 vol.
LOAD: 295 vol.
- Mainz Hbf | 25 vol.
- Karlsruhe Hbf | 70 vol.
- Freiburg Hbf | 65 vol.
- Stuttgart Hbf | 80 vol.
- Ulm Hbf | 55 vol.
LOAD: 30 vol.
- München Hbf | 30 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: 1220 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 50, 65, 35, 45, 80, 40, 25, 30, 45, 40, 75, 65, 70, 55, 65, 90, 45, 25, 85, 95, 30, 65] ITERATION Generation: #1 Best cost: 8291.078 | Path: [1, 2, 16, 5, 12, 22, 4, 1, 7, 11, 20, 13, 9, 19, 1, 8, 18, 10, 3, 17, 1, 15, 6, 14, 21, 1, 23, 1] Best cost: 7993.260 | Path: [1, 3, 19, 17, 14, 9, 1, 11, 7, 13, 20, 15, 1, 4, 10, 22, 12, 2, 16, 1, 8, 18, 5, 21, 23, 1, 6, 1] Best cost: 7910.046 | Path: [1, 4, 10, 8, 18, 22, 2, 16, 1, 7, 11, 13, 20, 3, 1, 12, 5, 19, 17, 23, 1, 21, 14, 6, 15, 1, 9, 1] Best cost: 7864.048 | Path: [1, 12, 2, 16, 5, 22, 4, 1, 7, 11, 13, 20, 3, 1, 18, 8, 10, 21, 17, 1, 19, 14, 6, 15, 9, 1, 23, 1] Best cost: 7861.573 | Path: [1, 15, 6, 14, 17, 1, 11, 7, 13, 20, 3, 1, 8, 18, 10, 4, 22, 12, 5, 1, 9, 23, 21, 19, 16, 1, 2, 1] Best cost: 7722.311 | Path: [1, 17, 14, 6, 15, 1, 7, 11, 13, 20, 3, 1, 4, 10, 22, 16, 2, 12, 1, 8, 18, 5, 19, 21, 23, 1, 9, 1] Best cost: 7683.572 | Path: [1, 5, 2, 16, 12, 22, 4, 1, 7, 11, 13, 20, 3, 1, 8, 18, 10, 14, 17, 19, 1, 21, 23, 6, 15, 1, 9, 1] Best cost: 7669.488 | Path: [1, 5, 16, 2, 12, 22, 4, 1, 11, 7, 13, 20, 3, 1, 18, 8, 10, 17, 14, 19, 1, 15, 6, 23, 21, 1, 9, 1] Best cost: 7614.276 | Path: [1, 6, 14, 17, 19, 4, 1, 7, 11, 13, 9, 15, 3, 1, 8, 18, 10, 22, 12, 2, 1, 16, 5, 21, 23, 1, 20, 1] Generation: #2 Best cost: 7594.780 | Path: [1, 2, 16, 5, 12, 22, 4, 1, 7, 11, 13, 20, 3, 1, 8, 18, 10, 21, 17, 1, 15, 6, 14, 23, 19, 1, 9, 1] OPTIMIZING each tour... Current: [[1, 2, 16, 5, 12, 22, 4, 1], [1, 7, 11, 13, 20, 3, 1], [1, 8, 18, 10, 21, 17, 1], [1, 15, 6, 14, 23, 19, 1], [1, 9, 1]] [1] Cost: 1373.556 to 1363.131 | Optimized: [1, 12, 2, 16, 5, 22, 4, 1] [2] Cost: 1377.153 to 1371.845 | Optimized: [1, 3, 20, 13, 11, 7, 1] [3] Cost: 1902.389 to 1891.560 | Optimized: [1, 18, 8, 10, 21, 17, 1] [4] Cost: 1771.550 to 1767.185 | Optimized: [1, 19, 14, 23, 6, 15, 1] ACO RESULTS [1/300 vol./1363.131 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [2/295 vol./1371.845 km] Berlin Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/300 vol./1891.560 km] Berlin Hbf -> Kiel Hbf -> Hamburg Hbf -> Bremen Hbf -> Saarbrücken Hbf -> Mannheim Hbf --> Berlin Hbf [4/295 vol./1767.185 km] Berlin Hbf -> Mainz Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [5/ 30 vol./1170.132 km] Berlin Hbf -> München Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7563.853 km.