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: 300 vol.
ACTIVE: 20 customers
- Kassel-Wilhelmshöhe (55 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (20 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (20 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (45 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (60 vol.)
- Ulm Hbf (70 vol.)
- Mannheim Hbf (45 vol.)
- Kiel Hbf (60 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (60 vol.)
- Osnabrück Hbf (40 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1683.565 km
LOAD: 285 vol.
- Würzburg Hbf | 60 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 45 vol.
- München Hbf | 20 vol.
- Nürnberg Hbf | 100 vol.
Tour 2
COST: 1264.264 km
LOAD: 275 vol.
- Dresden Hbf | 70 vol.
- Leipzig Hbf | 45 vol.
- Hannover Hbf | 20 vol.
- Bremen Hbf | 40 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 60 vol.
Tour 3
COST: 1391.086 km
LOAD: 245 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Dortmund Hbf | 90 vol.
- Aachen Hbf | 60 vol.
- Osnabrück Hbf | 40 vol.
Tour 4
COST: 1728.911 km
LOAD: 295 vol.
- Ulm Hbf | 70 vol.
- Stuttgart Hbf | 95 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 70 vol.
LOAD: 285 vol.
- Würzburg Hbf | 60 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 45 vol.
- München Hbf | 20 vol.
- Nürnberg Hbf | 100 vol.
LOAD: 275 vol.
- Dresden Hbf | 70 vol.
- Leipzig Hbf | 45 vol.
- Hannover Hbf | 20 vol.
- Bremen Hbf | 40 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 60 vol.
LOAD: 245 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Dortmund Hbf | 90 vol.
- Aachen Hbf | 60 vol.
- Osnabrück Hbf | 40 vol.
LOAD: 295 vol.
- Ulm Hbf | 70 vol.
- Stuttgart Hbf | 95 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 70 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: [1] Berlin Hbf | Number of cities: 24 | Total loads: 1100 vol. | Vehicle capacity: 300 vol. Loads: [55, 0, 0, 40, 20, 60, 95, 70, 40, 20, 40, 45, 90, 100, 60, 70, 0, 45, 60, 20, 60, 0, 40, 70] ITERATION Generation: #1 Best cost: 7250.461 | Path: [1, 0, 12, 22, 10, 4, 8, 1, 11, 7, 13, 20, 19, 1, 18, 14, 17, 3, 5, 9, 1, 15, 6, 23, 1] Best cost: 6901.061 | Path: [1, 3, 19, 17, 14, 6, 9, 4, 1, 7, 11, 0, 22, 12, 1, 8, 18, 10, 5, 20, 1, 13, 15, 23, 1] Best cost: 6747.304 | Path: [1, 4, 0, 12, 22, 10, 8, 1, 11, 7, 13, 20, 19, 1, 18, 5, 3, 17, 14, 9, 1, 6, 15, 23, 1] Best cost: 6662.085 | Path: [1, 8, 18, 4, 22, 10, 12, 1, 11, 7, 13, 20, 19, 1, 0, 3, 17, 14, 6, 1, 5, 23, 15, 9, 1] Best cost: 6639.195 | Path: [1, 9, 15, 6, 14, 17, 1, 7, 11, 13, 20, 19, 1, 12, 22, 10, 8, 18, 4, 1, 0, 3, 5, 23, 1] Best cost: 6566.708 | Path: [1, 10, 8, 18, 4, 22, 12, 1, 7, 11, 0, 20, 19, 3, 1, 13, 6, 15, 9, 1, 17, 14, 23, 5, 1] Best cost: 6516.925 | Path: [1, 12, 22, 10, 8, 18, 4, 1, 11, 7, 13, 20, 19, 1, 0, 3, 17, 14, 6, 1, 9, 15, 23, 5, 1] Best cost: 6490.840 | Path: [1, 18, 8, 10, 4, 22, 12, 1, 11, 7, 13, 20, 19, 1, 0, 3, 17, 14, 6, 1, 9, 15, 23, 5, 1] Best cost: 6456.351 | Path: [1, 13, 20, 3, 19, 17, 9, 1, 7, 11, 4, 10, 22, 0, 1, 5, 12, 8, 18, 1, 6, 14, 23, 15, 1] Best cost: 6352.787 | Path: [1, 8, 18, 10, 22, 12, 4, 1, 7, 11, 13, 20, 19, 1, 0, 3, 17, 14, 6, 1, 5, 23, 15, 9, 1] Best cost: 6220.467 | Path: [1, 13, 20, 3, 19, 17, 9, 1, 11, 7, 4, 10, 8, 18, 1, 22, 12, 5, 0, 1, 15, 6, 14, 23, 1] Best cost: 6215.148 | Path: [1, 13, 20, 3, 19, 17, 9, 1, 11, 7, 4, 10, 8, 18, 1, 0, 12, 5, 22, 1, 15, 6, 14, 23, 1] OPTIMIZING each tour... Current: [[1, 13, 20, 3, 19, 17, 9, 1], [1, 11, 7, 4, 10, 8, 18, 1], [1, 0, 12, 5, 22, 1], [1, 15, 6, 14, 23, 1]] [1] Cost: 1731.691 to 1683.565 | Optimized: [1, 20, 3, 19, 17, 9, 13, 1] [2] Cost: 1363.460 to 1264.264 | Optimized: [1, 7, 11, 4, 10, 8, 18, 1] ACO RESULTS [1/285 vol./1683.565 km] Berlin Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> München Hbf -> Nürnberg Hbf --> Berlin Hbf [2/275 vol./1264.264 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/245 vol./1391.086 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Aachen Hbf -> Osnabrück Hbf --> Berlin Hbf [4/295 vol./1728.911 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6067.826 km.