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 (40 vol.)
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (35 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (65 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (85 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (95 vol.)
- Saarbrücken Hbf (45 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1410.52 km
LOAD: 285 vol.
- Mainz Hbf | 95 vol.
- Mannheim Hbf | 70 vol.
- Karlsruhe Hbf | 85 vol.
- Frankfurt Hbf | 35 vol.
Tour 2
COST: 1351.104 km
LOAD: 285 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 100 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 65 vol.
Tour 3
COST: 1325.787 km
LOAD: 270 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 35 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 40 vol.
- Hannover Hbf | 50 vol.
Tour 4
COST: 1996.299 km
LOAD: 290 vol.
- Stuttgart Hbf | 60 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 45 vol.
- Aachen Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 40 vol.
Tour 5
COST: 732.557 km
LOAD: 70 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 35 vol.
LOAD: 285 vol.
- Mainz Hbf | 95 vol.
- Mannheim Hbf | 70 vol.
- Karlsruhe Hbf | 85 vol.
- Frankfurt Hbf | 35 vol.
LOAD: 285 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 100 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 65 vol.
LOAD: 270 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 35 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 40 vol.
- Hannover Hbf | 50 vol.
LOAD: 290 vol.
- Stuttgart Hbf | 60 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 45 vol.
- Aachen Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 40 vol.
LOAD: 70 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 35 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: 1200 vol. | Vehicle capacity: 300 vol. Loads: [40, 0, 40, 35, 50, 70, 60, 35, 35, 65, 40, 100, 20, 85, 85, 0, 35, 70, 35, 95, 0, 45, 85, 75] ITERATION Generation: #1 Best cost: 7759.361 | Path: [1, 0, 22, 12, 2, 16, 5, 1, 7, 11, 13, 9, 1, 8, 18, 10, 4, 3, 19, 1, 17, 14, 6, 23, 1, 21, 1] Best cost: 7605.336 | Path: [1, 3, 19, 17, 14, 1, 11, 7, 13, 9, 1, 8, 18, 10, 22, 12, 2, 16, 1, 4, 0, 5, 21, 23, 1, 6, 1] Best cost: 7584.407 | Path: [1, 12, 2, 16, 5, 21, 14, 1, 11, 7, 13, 9, 1, 18, 8, 10, 4, 22, 0, 1, 3, 19, 17, 6, 1, 23, 1] Best cost: 7395.620 | Path: [1, 14, 17, 3, 19, 1, 7, 11, 4, 22, 12, 1, 18, 8, 10, 16, 2, 5, 21, 1, 13, 9, 6, 23, 1, 0, 1] Best cost: 7365.793 | Path: [1, 19, 3, 17, 14, 1, 7, 11, 4, 22, 12, 1, 8, 18, 10, 2, 16, 5, 21, 1, 13, 9, 6, 23, 1, 0, 1] Best cost: 7278.644 | Path: [1, 17, 14, 6, 9, 12, 1, 11, 7, 0, 22, 10, 1, 4, 8, 18, 16, 2, 5, 3, 1, 13, 19, 21, 23, 1] Best cost: 7185.885 | Path: [1, 23, 14, 6, 17, 1, 11, 7, 13, 9, 1, 8, 18, 4, 22, 12, 2, 16, 1, 0, 3, 19, 21, 5, 1, 10, 1] Best cost: 7086.976 | Path: [1, 19, 3, 17, 14, 1, 7, 11, 4, 10, 8, 18, 1, 0, 12, 2, 16, 5, 21, 1, 13, 9, 6, 23, 1, 22, 1] Generation: #2 Best cost: 7064.550 | Path: [1, 3, 19, 17, 14, 1, 7, 11, 4, 10, 8, 18, 1, 0, 12, 2, 16, 5, 21, 1, 13, 9, 6, 23, 1, 22, 1] Best cost: 6990.931 | Path: [1, 14, 6, 23, 21, 3, 1, 11, 7, 13, 9, 1, 8, 18, 10, 22, 12, 2, 16, 1, 0, 19, 17, 5, 1, 4, 1] Generation: #3 Best cost: 6879.023 | Path: [1, 19, 3, 17, 14, 1, 11, 7, 13, 9, 1, 4, 10, 22, 12, 2, 16, 1, 0, 5, 21, 23, 6, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 19, 3, 17, 14, 1], [1, 11, 7, 13, 9, 1], [1, 4, 10, 22, 12, 2, 16, 1], [1, 0, 5, 21, 23, 6, 1], [1, 8, 18, 1]] [1] Cost: 1432.961 to 1410.520 | Optimized: [1, 19, 17, 14, 3, 1] [2] Cost: 1377.326 to 1351.104 | Optimized: [1, 7, 11, 13, 9, 1] [3] Cost: 1337.250 to 1325.787 | Optimized: [1, 12, 2, 16, 22, 10, 4, 1] [4] Cost: 1998.929 to 1996.299 | Optimized: [1, 6, 23, 21, 5, 0, 1] ACO RESULTS [1/285 vol./1410.520 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Frankfurt Hbf --> Berlin Hbf [2/285 vol./1351.104 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf [3/270 vol./1325.787 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf --> Berlin Hbf [4/290 vol./1996.299 km] Berlin Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [5/ 70 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6816.267 km.