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
- Kassel-Wilhelmshöhe (90 vol.)
- Düsseldorf Hbf (45 vol.)
- Frankfurt Hbf (35 vol.)
- Hannover Hbf (45 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (80 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (50 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (20 vol.)
- Saarbrücken Hbf (65 vol.)
- Osnabrück Hbf (65 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1891.337 km
LOAD: 295 vol.
- Frankfurt Hbf | 35 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 50 vol.
- Freiburg Hbf | 70 vol.
- Ulm Hbf | 20 vol.
- München Hbf | 80 vol.
Tour 2
COST: 1228.936 km
LOAD: 260 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Würzburg Hbf | 20 vol.
- Nürnberg Hbf | 65 vol.
- Dresden Hbf | 85 vol.
Tour 3
COST: 1618.037 km
LOAD: 280 vol.
- Saarbrücken Hbf | 65 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 45 vol.
- Osnabrück Hbf | 65 vol.
- Hannover Hbf | 45 vol.
Tour 4
COST: 732.557 km
LOAD: 185 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 95 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 35 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 50 vol.
- Freiburg Hbf | 70 vol.
- Ulm Hbf | 20 vol.
- München Hbf | 80 vol.
LOAD: 260 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Würzburg Hbf | 20 vol.
- Nürnberg Hbf | 65 vol.
- Dresden Hbf | 85 vol.
LOAD: 280 vol.
- Saarbrücken Hbf | 65 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 45 vol.
- Osnabrück Hbf | 65 vol.
- Hannover Hbf | 45 vol.
LOAD: 185 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 95 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: 1020 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 45, 35, 45, 0, 0, 85, 90, 80, 0, 0, 0, 65, 50, 20, 60, 20, 95, 20, 20, 65, 65, 70] ITERATION Generation: #1 Best cost: 6713.498 | Path: [1, 0, 22, 4, 8, 1, 7, 20, 13, 3, 19, 17, 14, 1, 2, 16, 21, 23, 15, 1, 18, 9, 1] Best cost: 6283.277 | Path: [1, 2, 16, 3, 19, 17, 14, 23, 1, 7, 20, 13, 9, 15, 1, 4, 8, 18, 22, 1, 0, 21, 1] Best cost: 6210.358 | Path: [1, 7, 0, 2, 16, 19, 1, 8, 18, 4, 22, 1, 9, 15, 14, 17, 3, 20, 13, 1, 21, 23, 1] Best cost: 6205.731 | Path: [1, 13, 20, 9, 15, 14, 17, 3, 1, 7, 0, 22, 4, 1, 8, 18, 2, 16, 1, 19, 21, 23, 1] Best cost: 6141.812 | Path: [1, 2, 16, 19, 3, 17, 14, 23, 1, 7, 13, 20, 15, 9, 1, 8, 18, 4, 22, 1, 0, 21, 1] Best cost: 6097.779 | Path: [1, 21, 17, 14, 15, 9, 13, 1, 7, 20, 3, 19, 16, 2, 1, 4, 22, 8, 18, 1, 0, 23, 1] Best cost: 6020.625 | Path: [1, 19, 3, 17, 14, 21, 23, 15, 20, 1, 7, 4, 22, 0, 1, 8, 18, 2, 16, 1, 13, 9, 1] Best cost: 5855.515 | Path: [1, 19, 3, 17, 14, 23, 21, 15, 20, 1, 7, 13, 9, 22, 1, 4, 0, 2, 16, 1, 8, 18, 1] Best cost: 5830.222 | Path: [1, 2, 16, 3, 19, 17, 14, 23, 1, 4, 22, 0, 20, 13, 1, 7, 9, 15, 21, 1, 8, 18, 1] Generation: #2 Best cost: 5801.821 | Path: [1, 9, 15, 14, 17, 3, 19, 21, 1, 7, 13, 20, 0, 1, 4, 22, 2, 16, 23, 1, 8, 18, 1] Best cost: 5489.880 | Path: [1, 3, 19, 17, 14, 23, 15, 9, 1, 7, 13, 20, 0, 1, 4, 22, 2, 16, 21, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 17, 14, 23, 15, 9, 1], [1, 7, 13, 20, 0, 1], [1, 4, 22, 2, 16, 21, 1], [1, 8, 18, 1]] [2] Cost: 1235.162 to 1228.936 | Optimized: [1, 0, 20, 13, 7, 1] [3] Cost: 1630.824 to 1618.037 | Optimized: [1, 21, 16, 2, 22, 4, 1] ACO RESULTS [1/295 vol./1891.337 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Ulm Hbf -> München Hbf --> Berlin Hbf [2/260 vol./1228.936 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/280 vol./1618.037 km] Berlin Hbf -> Saarbrücken Hbf -> Köln Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [4/185 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5470.867 km.