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: 18 customers
- Düsseldorf Hbf (50 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (55 vol.)
- Stuttgart Hbf (60 vol.)
- Hamburg Hbf (30 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (65 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (20 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (50 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (95 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1582.686 km
LOAD: 285 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 60 vol.
- Karlsruhe Hbf | 20 vol.
- Nürnberg Hbf | 85 vol.
Tour 2
COST: 1107.833 km
LOAD: 265 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 100 vol.
Tour 3
COST: 1295.867 km
LOAD: 265 vol.
- Köln Hbf | 65 vol.
- Aachen Hbf | 55 vol.
- Düsseldorf Hbf | 50 vol.
- Dortmund Hbf | 55 vol.
- Hannover Hbf | 40 vol.
Tour 4
COST: 1671.024 km
LOAD: 295 vol.
- Frankfurt Hbf | 90 vol.
- Mainz Hbf | 95 vol.
- Mannheim Hbf | 50 vol.
- Freiburg Hbf | 60 vol.
LOAD: 285 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 60 vol.
- Karlsruhe Hbf | 20 vol.
- Nürnberg Hbf | 85 vol.
LOAD: 265 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 100 vol.
LOAD: 265 vol.
- Köln Hbf | 65 vol.
- Aachen Hbf | 55 vol.
- Düsseldorf Hbf | 50 vol.
- Dortmund Hbf | 55 vol.
- Hannover Hbf | 40 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 90 vol.
- Mainz Hbf | 95 vol.
- Mannheim Hbf | 50 vol.
- Freiburg Hbf | 60 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: 1110 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 50, 90, 40, 55, 60, 0, 30, 80, 65, 0, 55, 85, 20, 40, 65, 50, 100, 95, 0, 0, 70, 60] ITERATION Generation: #1 Best cost: 6612.005 | Path: [1, 2, 16, 5, 12, 22, 1, 8, 18, 10, 4, 14, 15, 1, 19, 3, 17, 6, 1, 13, 9, 23, 1] Best cost: 6373.369 | Path: [1, 3, 19, 17, 14, 15, 1, 4, 10, 22, 12, 2, 1, 8, 18, 16, 5, 1, 9, 13, 6, 23, 1] Best cost: 6180.441 | Path: [1, 4, 10, 8, 18, 12, 1, 13, 9, 15, 6, 14, 1, 3, 19, 17, 23, 1, 16, 2, 5, 22, 1] Best cost: 6028.004 | Path: [1, 13, 9, 15, 6, 14, 1, 8, 18, 10, 4, 12, 1, 3, 19, 17, 23, 1, 22, 2, 16, 5, 1] Best cost: 5814.813 | Path: [1, 19, 3, 17, 14, 15, 1, 8, 18, 10, 22, 1, 4, 12, 2, 16, 5, 1, 13, 9, 6, 23, 1] Best cost: 5792.387 | Path: [1, 3, 19, 17, 14, 15, 1, 8, 18, 10, 22, 1, 4, 12, 2, 16, 5, 1, 13, 9, 6, 23, 1] Best cost: 5731.572 | Path: [1, 13, 9, 15, 6, 14, 1, 8, 18, 10, 22, 1, 4, 12, 2, 16, 5, 1, 19, 3, 17, 23, 1] Best cost: 5709.146 | Path: [1, 13, 9, 15, 6, 14, 1, 8, 18, 10, 22, 1, 4, 12, 2, 16, 5, 1, 3, 19, 17, 23, 1] OPTIMIZING each tour... Current: [[1, 13, 9, 15, 6, 14, 1], [1, 8, 18, 10, 22, 1], [1, 4, 12, 2, 16, 5, 1], [1, 3, 19, 17, 23, 1]] [1] Cost: 1591.202 to 1582.686 | Optimized: [1, 9, 15, 6, 14, 13, 1] [2] Cost: 1132.488 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] [3] Cost: 1314.432 to 1295.867 | Optimized: [1, 16, 5, 2, 12, 4, 1] ACO RESULTS [1/285 vol./1582.686 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Nürnberg Hbf --> Berlin Hbf [2/265 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/265 vol./1295.867 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Hannover Hbf --> Berlin Hbf [4/295 vol./1671.024 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5657.410 km.