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 (95 vol.)
- Düsseldorf Hbf (60 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (30 vol.)
- Dresden Hbf (60 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (80 vol.)
- Leipzig Hbf (90 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (40 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (60 vol.)
- Würzburg Hbf (70 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (75 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1495.714 km
LOAD: 385 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 40 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 60 vol.
- Mainz Hbf | 60 vol.
Tour 2
COST: 1355.556 km
LOAD: 360 vol.
- Köln Hbf | 40 vol.
- Aachen Hbf | 30 vol.
- Düsseldorf Hbf | 60 vol.
- Dortmund Hbf | 20 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 35 vol.
Tour 3
COST: 1312.378 km
LOAD: 400 vol.
- Würzburg Hbf | 70 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 90 vol.
- Dresden Hbf | 60 vol.
- Berlin Hbf | 95 vol.
Tour 4
COST: 362.286 km
LOAD: 85 vol.
- Hannover Hbf | 85 vol.
LOAD: 385 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 40 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 60 vol.
- Mainz Hbf | 60 vol.
LOAD: 360 vol.
- Köln Hbf | 40 vol.
- Aachen Hbf | 30 vol.
- Düsseldorf Hbf | 60 vol.
- Dortmund Hbf | 20 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 35 vol.
LOAD: 400 vol.
- Würzburg Hbf | 70 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 90 vol.
- Dresden Hbf | 60 vol.
- Berlin Hbf | 95 vol.
LOAD: 85 vol.
- Hannover Hbf | 85 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: 1230 vol. | Vehicle capacity: 400 vol. Loads: [0, 95, 60, 0, 85, 30, 0, 60, 20, 60, 80, 90, 20, 85, 100, 40, 40, 0, 35, 60, 70, 60, 75, 65] ITERATION Generation: #1 Best cost: 5427.057 | Path: [0, 1, 7, 11, 4, 8, 18, 0, 12, 2, 16, 5, 19, 20, 13, 0, 22, 10, 21, 14, 23, 0, 15, 9, 0] Best cost: 5146.368 | Path: [0, 7, 11, 1, 8, 18, 10, 12, 0, 19, 21, 14, 23, 15, 9, 0, 22, 4, 2, 16, 5, 20, 0, 13, 0] Best cost: 4876.670 | Path: [0, 1, 11, 7, 13, 20, 0, 4, 10, 22, 12, 2, 16, 5, 0, 19, 14, 23, 21, 15, 9, 0, 8, 18, 0] Best cost: 4814.325 | Path: [0, 5, 2, 16, 12, 22, 10, 4, 0, 19, 21, 14, 23, 15, 9, 0, 20, 13, 7, 11, 1, 0, 8, 18, 0] Best cost: 4700.867 | Path: [0, 19, 21, 23, 14, 15, 9, 0, 12, 2, 16, 5, 22, 10, 4, 0, 20, 13, 11, 7, 1, 0, 8, 18, 0] Best cost: 4681.239 | Path: [0, 22, 12, 2, 16, 5, 19, 14, 0, 4, 10, 8, 18, 1, 7, 0, 20, 13, 9, 15, 23, 21, 0, 11, 0] Best cost: 4619.080 | Path: [0, 22, 12, 2, 16, 5, 21, 14, 0, 4, 10, 8, 18, 1, 7, 0, 20, 13, 9, 15, 23, 19, 0, 11, 0] Best cost: 4569.038 | Path: [0, 9, 15, 14, 23, 21, 19, 0, 12, 2, 16, 5, 22, 10, 8, 18, 0, 20, 13, 7, 11, 1, 0, 4, 0] Generation: #2 Best cost: 4545.465 | Path: [0, 9, 15, 14, 23, 21, 19, 0, 12, 2, 16, 5, 22, 10, 8, 18, 0, 20, 13, 11, 7, 1, 0, 4, 0] OPTIMIZING each tour... Current: [[0, 9, 15, 14, 23, 21, 19, 0], [0, 12, 2, 16, 5, 22, 10, 8, 18, 0], [0, 20, 13, 11, 7, 1, 0], [0, 4, 0]] [2] Cost: 1375.087 to 1355.556 | Optimized: [0, 16, 5, 2, 12, 22, 10, 8, 18, 0] ACO RESULTS [1/385 vol./1495.714 km] Kassel-Wilhelmshöhe -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe [2/360 vol./1355.556 km] Kassel-Wilhelmshöhe -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Kassel-Wilhelmshöhe [3/400 vol./1312.378 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe [4/ 85 vol./ 362.286 km] Kassel-Wilhelmshöhe -> Hannover Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4525.934 km.