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: 19 customers
- Berlin Hbf (20 vol.)
- Düsseldorf Hbf (100 vol.)
- Hannover Hbf (20 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (90 vol.)
- Dresden Hbf (35 vol.)
- München Hbf (45 vol.)
- Bremen Hbf (80 vol.)
- Leipzig Hbf (80 vol.)
- Nürnberg Hbf (20 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (65 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (40 vol.)
- Mainz Hbf (50 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (40 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1690.337 km
LOAD: 390 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 75 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 80 vol.
- Hannover Hbf | 20 vol.
- Berlin Hbf | 20 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 80 vol.
Tour 2
COST: 1150.363 km
LOAD: 380 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 20 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 90 vol.
- Karlsruhe Hbf | 40 vol.
- Mannheim Hbf | 40 vol.
Tour 3
COST: 1209.244 km
LOAD: 275 vol.
- Düsseldorf Hbf | 100 vol.
- Saarbrücken Hbf | 40 vol.
- Freiburg Hbf | 85 vol.
- Mainz Hbf | 50 vol.
LOAD: 390 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 75 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 80 vol.
- Hannover Hbf | 20 vol.
- Berlin Hbf | 20 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 80 vol.
LOAD: 380 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 20 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 90 vol.
- Karlsruhe Hbf | 40 vol.
- Mannheim Hbf | 40 vol.
LOAD: 275 vol.
- Düsseldorf Hbf | 100 vol.
- Saarbrücken Hbf | 40 vol.
- Freiburg Hbf | 85 vol.
- Mainz Hbf | 50 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: 1045 vol. | Vehicle capacity: 400 vol. Loads: [0, 20, 100, 0, 20, 75, 90, 35, 0, 45, 80, 80, 0, 20, 40, 65, 60, 40, 0, 50, 80, 40, 20, 85] ITERATION Generation: #1 Best cost: 4602.303 | Path: [0, 1, 11, 7, 13, 20, 17, 14, 23, 0, 22, 10, 4, 16, 2, 5, 21, 0, 19, 6, 15, 9, 0] Best cost: 4563.248 | Path: [0, 2, 16, 5, 19, 17, 14, 13, 0, 22, 10, 4, 1, 11, 7, 9, 15, 0, 20, 6, 21, 23, 0] Best cost: 4454.508 | Path: [0, 5, 2, 16, 19, 17, 14, 13, 0, 22, 10, 4, 1, 7, 11, 9, 15, 0, 20, 6, 23, 21, 0] Best cost: 4308.541 | Path: [0, 1, 11, 7, 4, 10, 22, 16, 5, 0, 20, 13, 9, 15, 6, 14, 17, 0, 2, 19, 21, 23, 0] Best cost: 4299.286 | Path: [0, 1, 11, 7, 13, 9, 15, 6, 14, 0, 4, 10, 22, 2, 16, 5, 21, 0, 20, 19, 17, 23, 0] Best cost: 4234.046 | Path: [0, 7, 11, 1, 4, 10, 22, 16, 5, 0, 17, 14, 6, 15, 9, 13, 20, 0, 19, 21, 23, 2, 0] Best cost: 4219.791 | Path: [0, 7, 11, 1, 4, 10, 22, 16, 5, 0, 20, 13, 9, 15, 6, 14, 17, 0, 19, 21, 23, 2, 0] Generation: #3 Best cost: 4108.970 | Path: [0, 11, 7, 1, 4, 10, 22, 16, 5, 0, 20, 13, 9, 15, 6, 14, 17, 0, 2, 19, 21, 23, 0] OPTIMIZING each tour... Current: [[0, 11, 7, 1, 4, 10, 22, 16, 5, 0], [0, 20, 13, 9, 15, 6, 14, 17, 0], [0, 2, 19, 21, 23, 0]] [1] Cost: 1704.260 to 1690.337 | Optimized: [0, 16, 5, 22, 10, 4, 1, 7, 11, 0] [3] Cost: 1254.347 to 1209.244 | Optimized: [0, 2, 21, 23, 19, 0] ACO RESULTS [1/390 vol./1690.337 km] Kassel-Wilhelmshöhe -> Köln Hbf -> Aachen Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/380 vol./1150.363 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe [3/275 vol./1209.244 km] Kassel-Wilhelmshöhe -> Düsseldorf Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4049.944 km.