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: 400 vol.
ACTIVE: 18 customers
- Berlin Hbf (90 vol.)
- Düsseldorf Hbf (85 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (95 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (20 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (30 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (60 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (65 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (35 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (40 vol.)
Tour 1
COST: 1851.444 km
LOAD: 380 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 60 vol.
- Dresden Hbf | 20 vol.
- Berlin Hbf | 90 vol.
- Hamburg Hbf | 65 vol.
- Bremen Hbf | 30 vol.
- Hannover Hbf | 50 vol.
Tour 2
COST: 1347.625 km
LOAD: 350 vol.
- Frankfurt Hbf | 60 vol.
- Mannheim Hbf | 65 vol.
- Karlsruhe Hbf | 60 vol.
- Stuttgart Hbf | 50 vol.
- Freiburg Hbf | 40 vol.
- Saarbrücken Hbf | 35 vol.
- Würzburg Hbf | 40 vol.
Tour 3
COST: 757.62 km
LOAD: 345 vol.
- Osnabrück Hbf | 70 vol.
- Düsseldorf Hbf | 85 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 95 vol.
LOAD: 380 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 60 vol.
- Dresden Hbf | 20 vol.
- Berlin Hbf | 90 vol.
- Hamburg Hbf | 65 vol.
- Bremen Hbf | 30 vol.
- Hannover Hbf | 50 vol.
LOAD: 350 vol.
- Frankfurt Hbf | 60 vol.
- Mannheim Hbf | 65 vol.
- Karlsruhe Hbf | 60 vol.
- Stuttgart Hbf | 50 vol.
- Freiburg Hbf | 40 vol.
- Saarbrücken Hbf | 35 vol.
- Würzburg Hbf | 40 vol.
LOAD: 345 vol.
- Osnabrück Hbf | 70 vol.
- Düsseldorf Hbf | 85 vol.
- Aachen Hbf | 95 vol.
- Köln 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1075 vol. | Vehicle capacity: 400 vol. Loads: [0, 90, 85, 60, 50, 95, 50, 20, 65, 60, 30, 0, 0, 65, 60, 0, 95, 65, 0, 0, 40, 35, 70, 40] ITERATION Generation: #1 Best cost: 4622.365 | Path: [0, 1, 7, 4, 10, 8, 22, 3, 0, 20, 13, 9, 6, 14, 17, 21, 0, 2, 16, 5, 23, 0] Best cost: 4502.538 | Path: [0, 3, 17, 14, 6, 20, 13, 9, 0, 4, 10, 8, 22, 2, 16, 0, 5, 21, 23, 7, 1, 0] Best cost: 4426.071 | Path: [0, 5, 2, 16, 3, 17, 0, 22, 10, 8, 4, 1, 7, 20, 21, 0, 13, 9, 6, 14, 23, 0] Best cost: 4232.001 | Path: [0, 20, 13, 9, 6, 14, 17, 3, 0, 4, 8, 10, 22, 2, 16, 0, 5, 21, 23, 7, 1, 0] Best cost: 4190.583 | Path: [0, 20, 3, 17, 14, 6, 23, 21, 4, 0, 22, 10, 8, 1, 7, 13, 9, 0, 2, 16, 5, 0] Best cost: 4089.830 | Path: [0, 20, 13, 9, 6, 14, 17, 3, 0, 22, 4, 10, 8, 1, 7, 23, 21, 0, 2, 16, 5, 0] Generation: #7 Best cost: 4001.471 | Path: [0, 4, 10, 8, 1, 7, 13, 9, 0, 20, 3, 17, 14, 6, 23, 21, 0, 22, 2, 16, 5, 0] OPTIMIZING each tour... Current: [[0, 4, 10, 8, 1, 7, 13, 9, 0], [0, 20, 3, 17, 14, 6, 23, 21, 0], [0, 22, 2, 16, 5, 0]] [1] Cost: 1871.321 to 1851.444 | Optimized: [0, 13, 9, 7, 1, 8, 10, 4, 0] [2] Cost: 1352.511 to 1347.625 | Optimized: [0, 3, 17, 14, 6, 23, 21, 20, 0] [3] Cost: 777.639 to 757.620 | Optimized: [0, 22, 2, 5, 16, 0] ACO RESULTS [1/380 vol./1851.444 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Dresden Hbf -> Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe [2/350 vol./1347.625 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [3/345 vol./ 757.620 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3956.689 km.