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 (30 vol.)
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (75 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (60 vol.)
- Hamburg Hbf (25 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (60 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (65 vol.)
- Ulm Hbf (25 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (30 vol.)
- Kiel Hbf (60 vol.)
- Mainz Hbf (30 vol.)
- Würzburg Hbf (95 vol.)
- Osnabrück Hbf (95 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1950.93 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 30 vol.
- Frankfurt Hbf | 60 vol.
- Mainz Hbf | 30 vol.
- Mannheim Hbf | 30 vol.
- Freiburg Hbf | 35 vol.
- Stuttgart Hbf | 30 vol.
- Ulm Hbf | 25 vol.
- München Hbf | 60 vol.
Tour 2
COST: 1187.501 km
LOAD: 300 vol.
- Würzburg Hbf | 95 vol.
- Nürnberg Hbf | 65 vol.
- Leipzig Hbf | 80 vol.
- Dresden Hbf | 60 vol.
Tour 3
COST: 1303.182 km
LOAD: 290 vol.
- Dortmund Hbf | 50 vol.
- Osnabrück Hbf | 95 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 25 vol.
- Kiel Hbf | 60 vol.
Tour 4
COST: 1288.608 km
LOAD: 245 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 70 vol.
- Düsseldorf Hbf | 65 vol.
- Hannover Hbf | 75 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 30 vol.
- Frankfurt Hbf | 60 vol.
- Mainz Hbf | 30 vol.
- Mannheim Hbf | 30 vol.
- Freiburg Hbf | 35 vol.
- Stuttgart Hbf | 30 vol.
- Ulm Hbf | 25 vol.
- München Hbf | 60 vol.
LOAD: 300 vol.
- Würzburg Hbf | 95 vol.
- Nürnberg Hbf | 65 vol.
- Leipzig Hbf | 80 vol.
- Dresden Hbf | 60 vol.
LOAD: 290 vol.
- Dortmund Hbf | 50 vol.
- Osnabrück Hbf | 95 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 25 vol.
- Kiel Hbf | 60 vol.
LOAD: 245 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 70 vol.
- Düsseldorf Hbf | 65 vol.
- Hannover Hbf | 75 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: 1135 vol. | Vehicle capacity: 300 vol. Loads: [30, 0, 65, 60, 75, 70, 30, 60, 25, 60, 60, 80, 50, 65, 0, 25, 35, 30, 60, 30, 95, 0, 95, 35] ITERATION Generation: #1 Best cost: 6798.928 | Path: [1, 0, 12, 2, 16, 5, 19, 1, 11, 7, 13, 20, 1, 8, 18, 10, 4, 3, 1, 22, 17, 6, 15, 9, 23, 1] Best cost: 6574.105 | Path: [1, 3, 19, 17, 6, 15, 9, 13, 1, 7, 11, 4, 10, 8, 1, 18, 0, 12, 2, 16, 23, 1, 22, 5, 20, 1] Best cost: 6327.354 | Path: [1, 4, 22, 10, 8, 0, 1, 7, 11, 13, 20, 1, 18, 12, 2, 16, 5, 1, 9, 15, 6, 17, 3, 19, 23, 1] Best cost: 6169.015 | Path: [1, 7, 11, 4, 10, 8, 1, 18, 22, 12, 2, 0, 1, 13, 20, 3, 19, 17, 1, 9, 15, 6, 23, 16, 5, 1] Best cost: 6167.780 | Path: [1, 19, 3, 17, 20, 13, 1, 7, 11, 4, 10, 8, 1, 18, 22, 12, 2, 0, 1, 16, 5, 23, 6, 15, 9, 1] Generation: #2 Best cost: 6167.214 | Path: [1, 13, 20, 3, 19, 17, 1, 7, 11, 4, 10, 8, 1, 18, 22, 12, 2, 0, 1, 16, 5, 23, 6, 15, 9, 1] Best cost: 6121.054 | Path: [1, 12, 2, 16, 5, 19, 17, 1, 7, 11, 4, 10, 8, 1, 18, 22, 0, 20, 1, 13, 9, 15, 6, 23, 3, 1] Generation: #3 Best cost: 6043.311 | Path: [1, 9, 15, 6, 17, 19, 3, 23, 0, 1, 11, 7, 13, 20, 1, 18, 8, 10, 22, 12, 1, 4, 5, 16, 2, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 17, 19, 3, 23, 0, 1], [1, 11, 7, 13, 20, 1], [1, 18, 8, 10, 22, 12, 1], [1, 4, 5, 16, 2, 1]] [1] Cost: 2194.086 to 1950.930 | Optimized: [1, 0, 3, 19, 17, 23, 6, 15, 9, 1] [2] Cost: 1216.319 to 1187.501 | Optimized: [1, 20, 13, 11, 7, 1] [3] Cost: 1323.499 to 1303.182 | Optimized: [1, 12, 22, 10, 8, 18, 1] [4] Cost: 1309.407 to 1288.608 | Optimized: [1, 16, 5, 2, 4, 1] ACO RESULTS [1/300 vol./1950.930 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Freiburg Hbf -> Stuttgart Hbf -> Ulm Hbf -> München Hbf --> Berlin Hbf [2/300 vol./1187.501 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/290 vol./1303.182 km] Berlin Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/245 vol./1288.608 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Hannover Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5730.221 km.