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 (50 vol.)
- Hannover Hbf (75 vol.)
- Aachen Hbf (35 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (80 vol.)
- Nürnberg Hbf (65 vol.)
- Ulm Hbf (100 vol.)
- Mannheim Hbf (35 vol.)
- Kiel Hbf (60 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (70 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1396.214 km
LOAD: 390 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 70 vol.
- Freiburg Hbf | 85 vol.
- Mannheim Hbf | 35 vol.
Tour 2
COST: 1335.963 km
LOAD: 390 vol.
- Aachen Hbf | 35 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 60 vol.
- Hannover Hbf | 75 vol.
Tour 3
COST: 1312.378 km
LOAD: 355 vol.
- Würzburg Hbf | 70 vol.
- Nürnberg Hbf | 65 vol.
- Leipzig Hbf | 80 vol.
- Dresden Hbf | 90 vol.
- Berlin Hbf | 50 vol.
Tour 4
COST: 450.422 km
LOAD: 100 vol.
- Mainz Hbf | 100 vol.
LOAD: 390 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 70 vol.
- Freiburg Hbf | 85 vol.
- Mannheim Hbf | 35 vol.
LOAD: 390 vol.
- Aachen Hbf | 35 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 60 vol.
- Hannover Hbf | 75 vol.
LOAD: 355 vol.
- Würzburg Hbf | 70 vol.
- Nürnberg Hbf | 65 vol.
- Leipzig Hbf | 80 vol.
- Dresden Hbf | 90 vol.
- Berlin Hbf | 50 vol.
LOAD: 100 vol.
- Mainz Hbf | 100 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: 1235 vol. | Vehicle capacity: 400 vol. Loads: [0, 50, 0, 0, 75, 35, 70, 90, 40, 100, 95, 80, 0, 65, 0, 100, 0, 35, 60, 100, 70, 0, 85, 85] ITERATION Generation: #1 Best cost: 5361.117 | Path: [0, 1, 11, 7, 13, 20, 17, 0, 4, 22, 10, 8, 18, 5, 0, 19, 15, 6, 23, 0, 9, 0] Best cost: 5215.340 | Path: [0, 5, 22, 4, 10, 8, 18, 0, 20, 13, 9, 15, 17, 0, 19, 6, 23, 11, 1, 0, 7, 0] Best cost: 5004.854 | Path: [0, 7, 11, 1, 8, 18, 4, 0, 22, 10, 5, 19, 17, 0, 20, 13, 15, 6, 23, 0, 9, 0] Best cost: 4990.880 | Path: [0, 13, 9, 15, 6, 17, 0, 4, 22, 10, 8, 18, 5, 0, 19, 20, 11, 7, 1, 0, 23, 0] Best cost: 4728.803 | Path: [0, 11, 7, 1, 8, 18, 4, 0, 22, 10, 5, 19, 17, 0, 20, 13, 9, 15, 0, 6, 23, 0] Best cost: 4676.387 | Path: [0, 5, 19, 17, 23, 6, 20, 0, 4, 8, 18, 10, 22, 0, 13, 9, 15, 7, 0, 11, 1, 0] Generation: #3 Best cost: 4574.033 | Path: [0, 9, 15, 6, 23, 17, 0, 4, 10, 8, 18, 22, 5, 0, 20, 13, 11, 7, 1, 0, 19, 0] OPTIMIZING each tour... Current: [[0, 9, 15, 6, 23, 17, 0], [0, 4, 10, 8, 18, 22, 5, 0], [0, 20, 13, 11, 7, 1, 0], [0, 19, 0]] [2] Cost: 1415.019 to 1335.963 | Optimized: [0, 5, 22, 10, 8, 18, 4, 0] ACO RESULTS [1/390 vol./1396.214 km] Kassel-Wilhelmshöhe -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe [2/390 vol./1335.963 km] Kassel-Wilhelmshöhe -> Aachen Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe [3/355 vol./1312.378 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe [4/100 vol./ 450.422 km] Kassel-Wilhelmshöhe -> Mainz Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4494.977 km.