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: 20 customers
- Berlin Hbf (70 vol.)
- Düsseldorf Hbf (50 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (90 vol.)
- Hamburg Hbf (70 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (85 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (85 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (45 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (35 vol.)
- Saarbrücken Hbf (85 vol.)
- Osnabrück Hbf (60 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1053.136 km
LOAD: 390 vol.
- Hannover Hbf | 65 vol.
- Hamburg Hbf | 70 vol.
- Kiel Hbf | 25 vol.
- Bremen Hbf | 85 vol.
- Osnabrück Hbf | 60 vol.
- Dortmund Hbf | 85 vol.
Tour 2
COST: 1251.032 km
LOAD: 400 vol.
- Frankfurt Hbf | 55 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 85 vol.
- Aachen Hbf | 70 vol.
- Düsseldorf Hbf | 50 vol.
Tour 3
COST: 1618.176 km
LOAD: 380 vol.
- Würzburg Hbf | 35 vol.
- Stuttgart Hbf | 90 vol.
- Ulm Hbf | 45 vol.
- München Hbf | 100 vol.
- Leipzig Hbf | 40 vol.
- Berlin Hbf | 70 vol.
Tour 4
COST: 450.422 km
LOAD: 75 vol.
- Mainz Hbf | 75 vol.
LOAD: 390 vol.
- Hannover Hbf | 65 vol.
- Hamburg Hbf | 70 vol.
- Kiel Hbf | 25 vol.
- Bremen Hbf | 85 vol.
- Osnabrück Hbf | 60 vol.
- Dortmund Hbf | 85 vol.
LOAD: 400 vol.
- Frankfurt Hbf | 55 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 85 vol.
- Aachen Hbf | 70 vol.
- Düsseldorf Hbf | 50 vol.
LOAD: 380 vol.
- Würzburg Hbf | 35 vol.
- Stuttgart Hbf | 90 vol.
- Ulm Hbf | 45 vol.
- München Hbf | 100 vol.
- Leipzig Hbf | 40 vol.
- Berlin Hbf | 70 vol.
LOAD: 75 vol.
- Mainz 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1245 vol. | Vehicle capacity: 400 vol. Loads: [0, 70, 50, 55, 65, 70, 90, 0, 70, 100, 85, 40, 85, 0, 40, 45, 0, 20, 25, 75, 35, 85, 60, 80] ITERATION Generation: #1 Best cost: 6009.962 | Path: [0, 1, 11, 4, 10, 22, 2, 17, 0, 19, 3, 20, 6, 14, 23, 18, 0, 12, 5, 21, 15, 9, 0, 8, 0] Best cost: 5571.256 | Path: [0, 3, 19, 17, 14, 6, 15, 20, 11, 0, 4, 10, 22, 12, 2, 18, 0, 5, 21, 23, 9, 0, 8, 1, 0] Best cost: 5447.369 | Path: [0, 6, 14, 17, 3, 19, 21, 20, 0, 22, 12, 2, 5, 10, 18, 0, 4, 8, 1, 11, 9, 15, 0, 23, 0] Best cost: 5142.383 | Path: [0, 11, 1, 8, 18, 10, 4, 20, 0, 22, 12, 2, 5, 17, 14, 3, 0, 19, 21, 23, 6, 15, 0, 9, 0] Best cost: 5082.949 | Path: [0, 15, 6, 14, 17, 19, 3, 20, 11, 0, 22, 10, 8, 18, 4, 12, 0, 2, 5, 21, 23, 9, 0, 1, 0] Best cost: 4996.625 | Path: [0, 19, 3, 17, 14, 6, 15, 20, 11, 0, 22, 10, 4, 8, 18, 1, 0, 12, 2, 5, 21, 23, 0, 9, 0] Best cost: 4855.419 | Path: [0, 23, 14, 6, 15, 9, 20, 0, 22, 10, 8, 18, 4, 12, 0, 2, 5, 21, 17, 3, 19, 11, 0, 1, 0] Best cost: 4668.637 | Path: [0, 17, 14, 6, 15, 9, 20, 3, 0, 22, 10, 8, 18, 1, 11, 2, 0, 12, 5, 21, 23, 19, 0, 4, 0] Generation: #2 Best cost: 4640.397 | Path: [0, 17, 14, 6, 15, 9, 20, 3, 0, 4, 10, 8, 18, 1, 11, 0, 22, 12, 2, 5, 21, 0, 19, 23, 0] Best cost: 4470.706 | Path: [0, 22, 10, 8, 18, 4, 12, 0, 2, 5, 21, 23, 14, 17, 3, 0, 20, 6, 15, 9, 11, 1, 0, 19, 0] Generation: #6 Best cost: 4464.457 | Path: [0, 4, 10, 8, 18, 22, 12, 0, 2, 5, 21, 23, 14, 17, 3, 0, 20, 6, 15, 9, 11, 1, 0, 19, 0] OPTIMIZING each tour... Current: [[0, 4, 10, 8, 18, 22, 12, 0], [0, 2, 5, 21, 23, 14, 17, 3, 0], [0, 20, 6, 15, 9, 11, 1, 0], [0, 19, 0]] [1] Cost: 1132.002 to 1053.136 | Optimized: [0, 4, 8, 18, 10, 22, 12, 0] [2] Cost: 1263.857 to 1251.032 | Optimized: [0, 3, 17, 14, 23, 21, 5, 2, 0] ACO RESULTS [1/390 vol./1053.136 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf -> Bremen Hbf -> Osnabrück Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1251.032 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe [3/380 vol./1618.176 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Stuttgart Hbf -> Ulm Hbf -> München Hbf -> Leipzig Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe [4/ 75 vol./ 450.422 km] Kassel-Wilhelmshöhe -> Mainz Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4372.766 km.