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
- Kassel-Wilhelmshöhe (95 vol.)
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (75 vol.)
- Hannover Hbf (60 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (90 vol.)
- Dresden Hbf (65 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (65 vol.)
- Bremen Hbf (60 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (95 vol.)
- Nürnberg Hbf (30 vol.)
- Karlsruhe Hbf (85 vol.)
- Ulm Hbf (45 vol.)
- Köln Hbf (20 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (60 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (95 vol.)
Tour 1
COST: 1303.182 km
LOAD: 290 vol.
- Dortmund Hbf | 95 vol.
- Osnabrück Hbf | 95 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 20 vol.
Tour 2
COST: 1047.518 km
LOAD: 300 vol.
- Dresden Hbf | 65 vol.
- Leipzig Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Hannover Hbf | 60 vol.
Tour 3
COST: 1591.232 km
LOAD: 300 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 45 vol.
- Stuttgart Hbf | 90 vol.
- Mannheim Hbf | 70 vol.
Tour 4
COST: 1551.245 km
LOAD: 290 vol.
- Frankfurt Hbf | 75 vol.
- Mainz Hbf | 60 vol.
- Saarbrücken Hbf | 70 vol.
- Karlsruhe Hbf | 85 vol.
Tour 5
COST: 1303.404 km
LOAD: 120 vol.
- Aachen Hbf | 60 vol.
- Köln Hbf | 20 vol.
- Düsseldorf Hbf | 40 vol.
LOAD: 290 vol.
- Dortmund Hbf | 95 vol.
- Osnabrück Hbf | 95 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 20 vol.
LOAD: 300 vol.
- Dresden Hbf | 65 vol.
- Leipzig Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Hannover Hbf | 60 vol.
LOAD: 300 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 45 vol.
- Stuttgart Hbf | 90 vol.
- Mannheim Hbf | 70 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 75 vol.
- Mainz Hbf | 60 vol.
- Saarbrücken Hbf | 70 vol.
- Karlsruhe Hbf | 85 vol.
LOAD: 120 vol.
- Aachen Hbf | 60 vol.
- Köln Hbf | 20 vol.
- Düsseldorf Hbf | 40 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: 1300 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 40, 75, 60, 60, 90, 65, 20, 65, 60, 80, 95, 30, 85, 45, 20, 70, 20, 60, 0, 70, 95, 0] ITERATION Generation: #1 Best cost: 8036.495 | Path: [1, 0, 12, 2, 16, 13, 8, 1, 11, 7, 4, 10, 18, 1, 17, 14, 6, 15, 1, 22, 5, 21, 19, 1, 3, 9, 1] Best cost: 7907.057 | Path: [1, 2, 16, 5, 12, 4, 8, 1, 11, 7, 0, 19, 1, 18, 10, 22, 17, 15, 1, 13, 9, 6, 14, 1, 3, 21, 1] Best cost: 7720.505 | Path: [1, 3, 19, 17, 14, 1, 11, 7, 13, 9, 15, 1, 8, 10, 4, 22, 2, 16, 1, 18, 0, 12, 5, 1, 21, 6, 1] Best cost: 7605.178 | Path: [1, 4, 10, 8, 18, 22, 2, 1, 11, 7, 13, 9, 15, 1, 0, 12, 16, 5, 1, 19, 3, 17, 14, 1, 6, 21, 1] Best cost: 7540.131 | Path: [1, 7, 11, 4, 10, 8, 1, 18, 22, 2, 16, 5, 19, 1, 0, 12, 3, 13, 1, 15, 6, 14, 17, 1, 9, 21, 1] Best cost: 7486.620 | Path: [1, 12, 2, 16, 5, 21, 1, 7, 11, 0, 4, 1, 8, 18, 10, 22, 3, 13, 1, 17, 14, 6, 15, 1, 19, 9, 1] Best cost: 7478.494 | Path: [1, 13, 9, 15, 6, 17, 1, 11, 7, 0, 16, 2, 1, 4, 10, 8, 18, 22, 1, 12, 5, 19, 3, 1, 14, 21, 1] Best cost: 7129.873 | Path: [1, 17, 3, 19, 14, 1, 11, 7, 0, 4, 1, 8, 18, 10, 22, 12, 1, 13, 9, 15, 6, 21, 1, 2, 16, 5, 1] Best cost: 7123.563 | Path: [1, 5, 16, 2, 12, 4, 8, 1, 11, 7, 13, 9, 15, 1, 18, 10, 22, 0, 1, 17, 14, 6, 1, 3, 19, 21, 1] Best cost: 6996.526 | Path: [1, 3, 19, 17, 14, 1, 11, 7, 0, 4, 1, 8, 18, 10, 22, 12, 1, 13, 9, 15, 6, 21, 1, 5, 2, 16, 1] Best cost: 6895.603 | Path: [1, 8, 18, 10, 22, 12, 1, 7, 11, 0, 4, 1, 13, 9, 15, 6, 17, 1, 19, 3, 14, 21, 1, 2, 16, 5, 1] Best cost: 6886.962 | Path: [1, 14, 17, 19, 3, 1, 7, 11, 0, 4, 1, 8, 18, 10, 22, 12, 1, 13, 9, 15, 6, 21, 1, 2, 16, 5, 1] Best cost: 6876.337 | Path: [1, 13, 9, 15, 6, 17, 1, 7, 11, 0, 4, 1, 8, 18, 10, 22, 12, 1, 3, 19, 14, 21, 1, 2, 16, 5, 1] Best cost: 6876.133 | Path: [1, 14, 17, 19, 3, 1, 7, 11, 0, 4, 1, 18, 8, 10, 22, 12, 1, 13, 9, 15, 6, 21, 1, 2, 16, 5, 1] Generation: #2 Best cost: 6871.479 | Path: [1, 3, 19, 17, 14, 1, 7, 11, 0, 4, 1, 18, 8, 10, 22, 12, 1, 13, 9, 15, 6, 21, 1, 2, 16, 5, 1] Best cost: 6835.320 | Path: [1, 13, 9, 15, 6, 17, 1, 7, 11, 0, 4, 1, 8, 18, 10, 22, 12, 1, 14, 21, 19, 3, 1, 2, 16, 5, 1] Generation: #3 Best cost: 6828.578 | Path: [1, 7, 11, 0, 4, 1, 8, 18, 10, 22, 12, 1, 13, 9, 15, 6, 17, 1, 3, 19, 21, 14, 1, 2, 16, 5, 1] Generation: #4 Best cost: 6828.578 | Path: [1, 13, 9, 15, 6, 17, 1, 7, 11, 0, 4, 1, 8, 18, 10, 22, 12, 1, 3, 19, 21, 14, 1, 2, 16, 5, 1] Generation: #5 Best cost: 6817.749 | Path: [1, 18, 8, 10, 22, 12, 1, 7, 11, 0, 4, 1, 13, 9, 15, 6, 17, 1, 3, 19, 21, 14, 1, 2, 16, 5, 1] Best cost: 6816.898 | Path: [1, 18, 8, 10, 22, 12, 1, 7, 11, 0, 4, 1, 13, 9, 15, 6, 17, 1, 3, 19, 21, 14, 1, 5, 16, 2, 1] OPTIMIZING each tour... Current: [[1, 18, 8, 10, 22, 12, 1], [1, 7, 11, 0, 4, 1], [1, 13, 9, 15, 6, 17, 1], [1, 3, 19, 21, 14, 1], [1, 5, 16, 2, 1]] [1] Cost: 1323.499 to 1303.182 | Optimized: [1, 12, 22, 10, 8, 18, 1] ACO RESULTS [1/290 vol./1303.182 km] Berlin Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [2/300 vol./1047.518 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf --> Berlin Hbf [3/300 vol./1591.232 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Mannheim Hbf --> Berlin Hbf [4/290 vol./1551.245 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Karlsruhe Hbf --> Berlin Hbf [5/120 vol./1303.404 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6796.581 km.