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 (100 vol.)
- Frankfurt Hbf (20 vol.)
- Aachen Hbf (90 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (95 vol.)
- München Hbf (85 vol.)
- Leipzig Hbf (25 vol.)
- Dortmund Hbf (40 vol.)
- Nürnberg Hbf (20 vol.)
- Ulm Hbf (75 vol.)
- Köln Hbf (50 vol.)
- Mannheim Hbf (40 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (80 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (85 vol.)
- Osnabrück Hbf (25 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1120.054 km
LOAD: 390 vol.
- Frankfurt Hbf | 20 vol.
- Mainz Hbf | 80 vol.
- Saarbrücken Hbf | 85 vol.
- Aachen Hbf | 90 vol.
- Köln Hbf | 50 vol.
- Dortmund Hbf | 40 vol.
- Osnabrück Hbf | 25 vol.
Tour 2
COST: 1421.702 km
LOAD: 380 vol.
- Mannheim Hbf | 40 vol.
- Freiburg Hbf | 60 vol.
- Stuttgart Hbf | 50 vol.
- Ulm Hbf | 75 vol.
- München Hbf | 85 vol.
- Nürnberg Hbf | 20 vol.
- Würzburg Hbf | 50 vol.
Tour 3
COST: 1355.175 km
LOAD: 300 vol.
- Kiel Hbf | 80 vol.
- Berlin Hbf | 100 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 25 vol.
LOAD: 390 vol.
- Frankfurt Hbf | 20 vol.
- Mainz Hbf | 80 vol.
- Saarbrücken Hbf | 85 vol.
- Aachen Hbf | 90 vol.
- Köln Hbf | 50 vol.
- Dortmund Hbf | 40 vol.
- Osnabrück Hbf | 25 vol.
LOAD: 380 vol.
- Mannheim Hbf | 40 vol.
- Freiburg Hbf | 60 vol.
- Stuttgart Hbf | 50 vol.
- Ulm Hbf | 75 vol.
- München Hbf | 85 vol.
- Nürnberg Hbf | 20 vol.
- Würzburg Hbf | 50 vol.
LOAD: 300 vol.
- Kiel Hbf | 80 vol.
- Berlin Hbf | 100 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 25 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: 1070 vol. | Vehicle capacity: 400 vol. Loads: [0, 100, 0, 20, 0, 90, 50, 95, 0, 85, 0, 25, 40, 20, 0, 75, 50, 40, 80, 80, 50, 85, 25, 60] ITERATION Generation: #1 Best cost: 5612.085 | Path: [0, 1, 11, 7, 20, 3, 19, 13, 0, 12, 16, 5, 21, 17, 6, 22, 0, 18, 15, 9, 23, 0] Best cost: 4905.948 | Path: [0, 3, 19, 17, 6, 15, 20, 13, 11, 12, 0, 22, 16, 5, 21, 23, 9, 0, 18, 1, 7, 0] Best cost: 4331.175 | Path: [0, 6, 15, 9, 13, 20, 3, 19, 0, 12, 16, 5, 21, 17, 23, 22, 0, 11, 7, 1, 18, 0] Best cost: 4314.241 | Path: [0, 3, 19, 17, 21, 23, 6, 20, 0, 12, 16, 5, 22, 18, 1, 0, 11, 7, 13, 9, 15, 0] Best cost: 4224.725 | Path: [0, 11, 7, 1, 18, 22, 12, 3, 0, 20, 13, 9, 15, 6, 17, 19, 0, 16, 5, 21, 23, 0] Best cost: 4166.654 | Path: [0, 6, 15, 9, 13, 20, 3, 19, 0, 22, 12, 16, 5, 21, 17, 23, 0, 11, 7, 1, 18, 0] Generation: #2 Best cost: 4160.192 | Path: [0, 20, 13, 9, 15, 6, 17, 3, 16, 0, 22, 12, 5, 21, 23, 19, 0, 11, 7, 1, 18, 0] Generation: #3 Best cost: 4071.091 | Path: [0, 6, 15, 9, 13, 20, 3, 19, 0, 12, 22, 18, 1, 7, 11, 0, 16, 5, 21, 23, 17, 0] Generation: #4 Best cost: 4056.861 | Path: [0, 6, 15, 9, 13, 20, 3, 19, 0, 22, 12, 16, 5, 21, 23, 17, 0, 11, 7, 1, 18, 0] Generation: #5 Best cost: 4002.544 | Path: [0, 22, 12, 16, 5, 21, 19, 3, 0, 20, 13, 9, 15, 6, 17, 23, 0, 11, 7, 1, 18, 0] OPTIMIZING each tour... Current: [[0, 22, 12, 16, 5, 21, 19, 3, 0], [0, 20, 13, 9, 15, 6, 17, 23, 0], [0, 11, 7, 1, 18, 0]] [1] Cost: 1126.690 to 1120.054 | Optimized: [0, 3, 19, 21, 5, 16, 12, 22, 0] [2] Cost: 1515.535 to 1421.702 | Optimized: [0, 17, 23, 6, 15, 9, 13, 20, 0] [3] Cost: 1360.319 to 1355.175 | Optimized: [0, 18, 1, 7, 11, 0] ACO RESULTS [1/390 vol./1120.054 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe [2/380 vol./1421.702 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Freiburg Hbf -> Stuttgart Hbf -> Ulm Hbf -> München Hbf -> Nürnberg Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [3/300 vol./1355.175 km] Kassel-Wilhelmshöhe -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3896.931 km.