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: 22 customers
- Berlin Hbf (20 vol.)
- Düsseldorf Hbf (70 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (45 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (65 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (75 vol.)
- Ulm Hbf (50 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (85 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (75 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (100 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1410.352 km
LOAD: 390 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 60 vol.
- Aachen Hbf | 45 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 70 vol.
- Dortmund Hbf | 60 vol.
- Osnabrück Hbf | 100 vol.
Tour 2
COST: 1453.615 km
LOAD: 370 vol.
- Hannover Hbf | 40 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 85 vol.
- Berlin Hbf | 20 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 50 vol.
Tour 3
COST: 1120.998 km
LOAD: 380 vol.
- Würzburg Hbf | 75 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 50 vol.
- Karlsruhe Hbf | 75 vol.
Tour 4
COST: 594.716 km
LOAD: 240 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 90 vol.
- Frankfurt Hbf | 95 vol.
LOAD: 390 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 60 vol.
- Aachen Hbf | 45 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 70 vol.
- Dortmund Hbf | 60 vol.
- Osnabrück Hbf | 100 vol.
LOAD: 370 vol.
- Hannover Hbf | 40 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 85 vol.
- Berlin Hbf | 20 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 50 vol.
LOAD: 380 vol.
- Würzburg Hbf | 75 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 50 vol.
- Karlsruhe Hbf | 75 vol.
LOAD: 240 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 90 vol.
- Frankfurt 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: 1380 vol. | Vehicle capacity: 400 vol. Loads: [0, 20, 70, 95, 40, 45, 0, 75, 35, 95, 65, 50, 60, 85, 75, 50, 30, 90, 85, 55, 75, 60, 100, 25] ITERATION Generation: #1 Best cost: 5273.416 | Path: [0, 1, 7, 11, 3, 19, 17, 0, 20, 13, 15, 9, 14, 0, 22, 10, 8, 18, 4, 12, 0, 5, 2, 16, 21, 23, 0] Best cost: 5057.540 | Path: [0, 11, 7, 1, 8, 18, 10, 4, 16, 0, 22, 12, 2, 5, 21, 19, 0, 3, 17, 14, 23, 15, 0, 20, 13, 9, 0] Best cost: 5039.218 | Path: [0, 22, 12, 2, 16, 5, 19, 23, 0, 4, 10, 8, 18, 1, 11, 7, 0, 20, 3, 17, 14, 21, 0, 13, 9, 15, 0] Best cost: 5034.987 | Path: [0, 13, 20, 3, 19, 17, 0, 22, 12, 2, 16, 5, 21, 23, 0, 4, 10, 8, 18, 1, 11, 7, 0, 14, 15, 9, 0] Best cost: 4693.288 | Path: [0, 13, 9, 15, 14, 17, 0, 22, 12, 2, 16, 5, 21, 23, 0, 4, 10, 8, 18, 1, 11, 7, 0, 20, 3, 19, 0] Generation: #2 Best cost: 4687.656 | Path: [0, 22, 12, 2, 16, 5, 21, 23, 0, 4, 10, 8, 18, 1, 11, 7, 0, 20, 13, 9, 15, 14, 0, 3, 19, 17, 0] OPTIMIZING each tour... Current: [[0, 22, 12, 2, 16, 5, 21, 23, 0], [0, 4, 10, 8, 18, 1, 11, 7, 0], [0, 20, 13, 9, 15, 14, 0], [0, 3, 19, 17, 0]] [1] Cost: 1418.821 to 1410.352 | Optimized: [0, 23, 21, 5, 16, 2, 12, 22, 0] [2] Cost: 1548.627 to 1453.615 | Optimized: [0, 4, 10, 8, 18, 1, 7, 11, 0] [4] Cost: 599.210 to 594.716 | Optimized: [0, 19, 17, 3, 0] ACO RESULTS [1/390 vol./1410.352 km] Kassel-Wilhelmshöhe -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe [2/370 vol./1453.615 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/380 vol./1120.998 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf --> Kassel-Wilhelmshöhe [4/240 vol./ 594.716 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Mannheim Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4579.681 km.