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: 21 customers
- Kassel-Wilhelmshöhe (100 vol.)
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (25 vol.)
- Dresden Hbf (65 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (75 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (100 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (75 vol.)
- Mainz Hbf (35 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (30 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1589.414 km
LOAD: 280 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 25 vol.
- Karlsruhe Hbf | 55 vol.
- Mannheim Hbf | 85 vol.
Tour 2
COST: 1179.657 km
LOAD: 285 vol.
- Dresden Hbf | 65 vol.
- Leipzig Hbf | 50 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Osnabrück Hbf | 30 vol.
- Hannover Hbf | 40 vol.
Tour 3
COST: 1295.458 km
LOAD: 275 vol.
- Dortmund Hbf | 100 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 65 vol.
- Kiel Hbf | 75 vol.
Tour 4
COST: 1747.015 km
LOAD: 245 vol.
- Frankfurt Hbf | 60 vol.
- Mainz Hbf | 35 vol.
- Saarbrücken Hbf | 60 vol.
- Freiburg Hbf | 90 vol.
Tour 5
COST: 1303.404 km
LOAD: 235 vol.
- Aachen Hbf | 75 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 65 vol.
LOAD: 280 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 25 vol.
- Karlsruhe Hbf | 55 vol.
- Mannheim Hbf | 85 vol.
LOAD: 285 vol.
- Dresden Hbf | 65 vol.
- Leipzig Hbf | 50 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Osnabrück Hbf | 30 vol.
- Hannover Hbf | 40 vol.
LOAD: 275 vol.
- Dortmund Hbf | 100 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 65 vol.
- Kiel Hbf | 75 vol.
LOAD: 245 vol.
- Frankfurt Hbf | 60 vol.
- Mainz Hbf | 35 vol.
- Saarbrücken Hbf | 60 vol.
- Freiburg Hbf | 90 vol.
LOAD: 235 vol.
- Aachen Hbf | 75 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 65 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: 1320 vol. | Vehicle capacity: 300 vol. Loads: [100, 0, 65, 60, 40, 75, 25, 65, 65, 75, 35, 50, 100, 0, 55, 40, 95, 85, 75, 35, 0, 60, 30, 90] ITERATION Generation: #1 Best cost: 8486.918 | Path: [1, 0, 12, 2, 19, 1, 11, 7, 4, 10, 8, 22, 1, 18, 6, 14, 17, 3, 1, 16, 5, 21, 15, 1, 9, 23, 1] Best cost: 7984.143 | Path: [1, 2, 16, 5, 19, 6, 1, 11, 7, 4, 22, 10, 8, 1, 18, 12, 0, 1, 3, 17, 14, 21, 15, 1, 9, 23, 1] Best cost: 7748.753 | Path: [1, 3, 19, 17, 14, 6, 15, 1, 11, 7, 4, 22, 10, 8, 1, 18, 0, 12, 1, 2, 16, 5, 21, 1, 9, 23, 1] Best cost: 7699.795 | Path: [1, 19, 3, 17, 14, 6, 15, 1, 11, 7, 0, 22, 10, 1, 8, 18, 4, 12, 1, 2, 16, 5, 21, 1, 9, 23, 1] Best cost: 7662.753 | Path: [1, 3, 19, 17, 14, 6, 15, 1, 7, 11, 0, 22, 10, 1, 8, 18, 4, 12, 1, 5, 2, 16, 21, 1, 9, 23, 1] Best cost: 7603.213 | Path: [1, 5, 16, 2, 22, 10, 1, 7, 11, 4, 8, 18, 1, 0, 12, 3, 19, 1, 6, 15, 14, 17, 21, 1, 9, 23, 1] Best cost: 7337.293 | Path: [1, 17, 14, 6, 15, 9, 1, 7, 11, 0, 22, 4, 1, 8, 18, 10, 12, 1, 5, 2, 16, 19, 1, 3, 21, 23, 1] Best cost: 7220.472 | Path: [1, 9, 15, 6, 14, 17, 1, 11, 7, 0, 22, 4, 1, 18, 8, 10, 12, 1, 3, 19, 21, 23, 1, 2, 16, 5, 1] Generation: #5 Best cost: 7155.814 | Path: [1, 9, 15, 6, 14, 17, 1, 7, 11, 0, 22, 4, 1, 8, 18, 10, 12, 1, 3, 19, 21, 23, 1, 16, 2, 5, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 14, 17, 1], [1, 7, 11, 0, 22, 4, 1], [1, 8, 18, 10, 12, 1], [1, 3, 19, 21, 23, 1], [1, 16, 2, 5, 1]] [3] Cost: 1315.948 to 1295.458 | Optimized: [1, 12, 10, 8, 18, 1] [5] Cost: 1323.780 to 1303.404 | Optimized: [1, 5, 16, 2, 1] ACO RESULTS [1/280 vol./1589.414 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Berlin Hbf [2/285 vol./1179.657 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [3/275 vol./1295.458 km] Berlin Hbf -> Dortmund Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/245 vol./1747.015 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf --> Berlin Hbf [5/235 vol./1303.404 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7114.948 km.