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: 17 customers
- Berlin Hbf (45 vol.)
- Düsseldorf Hbf (20 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (35 vol.)
- Stuttgart Hbf (20 vol.)
- Hamburg Hbf (30 vol.)
- München Hbf (65 vol.)
- Bremen Hbf (90 vol.)
- Dortmund Hbf (95 vol.)
- Nürnberg Hbf (50 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (25 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (25 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1387.379 km
LOAD: 395 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 90 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 20 vol.
- Köln Hbf | 55 vol.
- Aachen Hbf | 35 vol.
- Saarbrücken Hbf | 25 vol.
- Mannheim Hbf | 25 vol.
Tour 2
COST: 1388.078 km
LOAD: 395 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 50 vol.
- München Hbf | 65 vol.
- Stuttgart Hbf | 20 vol.
- Freiburg Hbf | 80 vol.
- Frankfurt Hbf | 95 vol.
Tour 3
COST: 1006.826 km
LOAD: 120 vol.
- Hannover Hbf | 45 vol.
- Hamburg Hbf | 30 vol.
- Berlin Hbf | 45 vol.
LOAD: 395 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 90 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 20 vol.
- Köln Hbf | 55 vol.
- Aachen Hbf | 35 vol.
- Saarbrücken Hbf | 25 vol.
- Mannheim Hbf | 25 vol.
LOAD: 395 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 50 vol.
- München Hbf | 65 vol.
- Stuttgart Hbf | 20 vol.
- Freiburg Hbf | 80 vol.
- Frankfurt Hbf | 95 vol.
LOAD: 120 vol.
- Hannover Hbf | 45 vol.
- Hamburg Hbf | 30 vol.
- Berlin Hbf | 45 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: 910 vol. | Vehicle capacity: 400 vol. Loads: [0, 45, 20, 95, 45, 35, 20, 0, 30, 65, 90, 0, 95, 50, 0, 0, 55, 25, 0, 0, 85, 25, 50, 80] ITERATION Generation: #1 Best cost: 4830.348 | Path: [0, 1, 4, 8, 10, 22, 12, 2, 21, 0, 3, 17, 6, 20, 13, 9, 5, 0, 16, 23, 0] Best cost: 4798.847 | Path: [0, 2, 16, 5, 12, 22, 10, 4, 0, 20, 13, 9, 6, 17, 3, 21, 8, 0, 23, 1, 0] Best cost: 4674.008 | Path: [0, 3, 17, 6, 20, 13, 9, 21, 2, 0, 4, 22, 10, 8, 1, 16, 5, 0, 12, 23, 0] Best cost: 4466.299 | Path: [0, 5, 16, 2, 12, 22, 4, 10, 0, 3, 17, 21, 23, 13, 20, 6, 0, 8, 1, 9, 0] Best cost: 4373.160 | Path: [0, 16, 2, 12, 22, 10, 8, 4, 0, 3, 17, 21, 23, 6, 20, 13, 0, 5, 9, 1, 0] Best cost: 4365.226 | Path: [0, 8, 4, 22, 12, 2, 16, 5, 21, 17, 6, 0, 3, 20, 13, 9, 23, 0, 10, 1, 0] Best cost: 4021.752 | Path: [0, 10, 22, 12, 2, 16, 5, 17, 21, 0, 3, 20, 13, 9, 6, 23, 0, 4, 8, 1, 0] Best cost: 3924.164 | Path: [0, 10, 22, 12, 16, 2, 5, 21, 17, 0, 3, 20, 13, 9, 6, 23, 0, 4, 8, 1, 0] Generation: #2 Best cost: 3894.220 | Path: [0, 10, 22, 12, 2, 16, 5, 21, 17, 0, 3, 20, 13, 9, 6, 23, 0, 4, 8, 1, 0] OPTIMIZING each tour... Current: [[0, 10, 22, 12, 2, 16, 5, 21, 17, 0], [0, 3, 20, 13, 9, 6, 23, 0], [0, 4, 8, 1, 0]] [1] Cost: 1405.716 to 1387.379 | Optimized: [0, 22, 10, 12, 2, 16, 5, 21, 17, 0] [2] Cost: 1481.678 to 1388.078 | Optimized: [0, 20, 13, 9, 6, 23, 3, 0] ACO RESULTS [1/395 vol./1387.379 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe [2/395 vol./1388.078 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/120 vol./1006.826 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3782.283 km.