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 (30 vol.)
- Düsseldorf Hbf (85 vol.)
- Frankfurt Hbf (100 vol.)
- Stuttgart Hbf (75 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (50 vol.)
- München Hbf (90 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (70 vol.)
- Nürnberg Hbf (20 vol.)
- Karlsruhe Hbf (90 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (80 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (65 vol.)
- Osnabrück Hbf (55 vol.)
Tour 1
COST: 1367.811 km
LOAD: 390 vol.
- Leipzig Hbf | 20 vol.
- Nürnberg Hbf | 20 vol.
- München Hbf | 90 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 75 vol.
- Karlsruhe Hbf | 90 vol.
Tour 2
COST: 931.148 km
LOAD: 400 vol.
- Mannheim Hbf | 80 vol.
- Saarbrücken Hbf | 65 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 100 vol.
- Würzburg Hbf | 60 vol.
Tour 3
COST: 1433.199 km
LOAD: 385 vol.
- Osnabrück Hbf | 55 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 100 vol.
- Berlin Hbf | 30 vol.
- Dresden Hbf | 75 vol.
Tour 4
COST: 509.83 km
LOAD: 215 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 85 vol.
- Köln Hbf | 60 vol.
LOAD: 390 vol.
- Leipzig Hbf | 20 vol.
- Nürnberg Hbf | 20 vol.
- München Hbf | 90 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 75 vol.
- Karlsruhe Hbf | 90 vol.
LOAD: 400 vol.
- Mannheim Hbf | 80 vol.
- Saarbrücken Hbf | 65 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 100 vol.
- Würzburg Hbf | 60 vol.
LOAD: 385 vol.
- Osnabrück Hbf | 55 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 100 vol.
- Berlin Hbf | 30 vol.
- Dresden Hbf | 75 vol.
LOAD: 215 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 85 vol.
- Köln Hbf | 60 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: 1390 vol. | Vehicle capacity: 400 vol. Loads: [0, 30, 85, 100, 0, 0, 75, 75, 50, 90, 75, 20, 70, 20, 90, 95, 60, 80, 100, 95, 60, 65, 55, 0] ITERATION Generation: #1 Best cost: 5604.808 | Path: [0, 1, 11, 7, 13, 20, 19, 3, 0, 12, 2, 16, 22, 10, 8, 0, 18, 14, 6, 15, 0, 17, 21, 9, 0] Best cost: 5444.761 | Path: [0, 3, 19, 17, 14, 13, 0, 12, 2, 16, 22, 10, 8, 0, 7, 11, 1, 18, 20, 6, 0, 21, 15, 9, 0] Best cost: 5107.675 | Path: [0, 6, 14, 17, 3, 13, 11, 0, 12, 2, 16, 19, 21, 0, 20, 15, 9, 7, 1, 8, 0, 22, 10, 18, 0] Best cost: 4823.792 | Path: [0, 9, 15, 6, 14, 13, 11, 0, 12, 2, 16, 19, 17, 0, 22, 10, 8, 18, 1, 7, 0, 3, 20, 21, 0] Best cost: 4611.479 | Path: [0, 22, 10, 8, 18, 1, 7, 0, 12, 2, 16, 3, 17, 0, 20, 13, 9, 15, 6, 11, 0, 19, 14, 21, 0] Best cost: 4603.196 | Path: [0, 14, 6, 15, 9, 13, 11, 0, 12, 2, 16, 19, 17, 0, 22, 10, 8, 18, 1, 7, 0, 3, 20, 21, 0] Best cost: 4510.347 | Path: [0, 14, 6, 15, 9, 13, 11, 0, 22, 10, 8, 18, 1, 7, 0, 12, 2, 16, 19, 17, 0, 20, 3, 21, 0] Generation: #2 Best cost: 4476.402 | Path: [0, 12, 2, 16, 3, 17, 0, 20, 6, 14, 21, 19, 0, 22, 10, 8, 18, 1, 7, 0, 11, 13, 9, 15, 0] Generation: #4 Best cost: 4454.061 | Path: [0, 6, 14, 17, 19, 20, 0, 22, 10, 8, 18, 1, 7, 0, 3, 21, 15, 9, 13, 11, 0, 12, 2, 16, 0] Generation: #5 Best cost: 4290.468 | Path: [0, 14, 6, 15, 9, 13, 11, 0, 20, 3, 19, 17, 21, 0, 22, 10, 8, 18, 1, 7, 0, 12, 2, 16, 0] OPTIMIZING each tour... Current: [[0, 14, 6, 15, 9, 13, 11, 0], [0, 20, 3, 19, 17, 21, 0], [0, 22, 10, 8, 18, 1, 7, 0], [0, 12, 2, 16, 0]] [1] Cost: 1377.818 to 1367.811 | Optimized: [0, 11, 13, 9, 15, 6, 14, 0] [2] Cost: 969.621 to 931.148 | Optimized: [0, 17, 21, 19, 3, 20, 0] ACO RESULTS [1/390 vol./1367.811 km] Kassel-Wilhelmshöhe -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf --> Kassel-Wilhelmshöhe [2/400 vol./ 931.148 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [3/385 vol./1433.199 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf --> Kassel-Wilhelmshöhe [4/215 vol./ 509.830 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4241.988 km.