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 (50 vol.)
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (25 vol.)
- Aachen Hbf (95 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (30 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (85 vol.)
- Nürnberg Hbf (35 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (30 vol.)
- Köln Hbf (100 vol.)
- Mannheim Hbf (45 vol.)
- Kiel Hbf (40 vol.)
- Mainz Hbf (30 vol.)
- Würzburg Hbf (75 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (25 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1764.462 km
LOAD: 300 vol.
- Mannheim Hbf | 45 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 70 vol.
- Mainz Hbf | 30 vol.
- Frankfurt Hbf | 25 vol.
Tour 2
COST: 1544.628 km
LOAD: 285 vol.
- Dresden Hbf | 25 vol.
- Nürnberg Hbf | 35 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 95 vol.
- Würzburg Hbf | 75 vol.
Tour 3
COST: 1256.055 km
LOAD: 230 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Osnabrück Hbf | 25 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 40 vol.
Tour 4
COST: 1303.404 km
LOAD: 275 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 100 vol.
- Düsseldorf Hbf | 80 vol.
LOAD: 300 vol.
- Mannheim Hbf | 45 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 70 vol.
- Mainz Hbf | 30 vol.
- Frankfurt Hbf | 25 vol.
LOAD: 285 vol.
- Dresden Hbf | 25 vol.
- Nürnberg Hbf | 35 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 95 vol.
- Würzburg Hbf | 75 vol.
LOAD: 230 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Osnabrück Hbf | 25 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 40 vol.
LOAD: 275 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 100 vol.
- Düsseldorf Hbf | 80 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: 1090 vol. | Vehicle capacity: 300 vol. Loads: [50, 0, 80, 25, 0, 95, 95, 25, 30, 25, 85, 0, 0, 35, 65, 30, 100, 45, 40, 30, 75, 70, 25, 65] ITERATION Generation: #1 Best cost: 7057.457 | Path: [1, 0, 16, 2, 22, 8, 1, 7, 13, 20, 3, 19, 17, 14, 1, 10, 18, 5, 21, 1, 15, 6, 23, 9, 1] Best cost: 6997.612 | Path: [1, 2, 16, 5, 3, 1, 7, 13, 20, 6, 14, 1, 8, 18, 10, 22, 0, 19, 15, 1, 17, 21, 23, 9, 1] Best cost: 6986.503 | Path: [1, 5, 2, 16, 22, 1, 7, 13, 20, 3, 19, 17, 14, 1, 8, 18, 10, 0, 21, 9, 1, 15, 6, 23, 1] Best cost: 6124.206 | Path: [1, 9, 15, 6, 14, 17, 3, 1, 7, 13, 20, 19, 21, 23, 1, 8, 18, 10, 22, 0, 1, 2, 16, 5, 1] Best cost: 6123.355 | Path: [1, 9, 15, 6, 14, 17, 3, 1, 7, 13, 20, 19, 21, 23, 1, 8, 18, 10, 22, 0, 1, 5, 16, 2, 1] Best cost: 6088.217 | Path: [1, 17, 14, 6, 15, 9, 13, 1, 7, 20, 3, 19, 21, 23, 1, 0, 22, 10, 8, 18, 1, 16, 2, 5, 1] Best cost: 6013.348 | Path: [1, 3, 19, 17, 14, 23, 21, 1, 7, 13, 20, 6, 15, 9, 1, 8, 18, 10, 22, 0, 1, 16, 2, 5, 1] Generation: #2 Best cost: 5996.527 | Path: [1, 21, 23, 14, 17, 19, 3, 1, 7, 13, 20, 6, 15, 9, 1, 8, 18, 10, 22, 0, 1, 2, 16, 5, 1] OPTIMIZING each tour... Current: [[1, 21, 23, 14, 17, 19, 3, 1], [1, 7, 13, 20, 6, 15, 9, 1], [1, 8, 18, 10, 22, 0, 1], [1, 2, 16, 5, 1]] [1] Cost: 1805.023 to 1764.462 | Optimized: [1, 17, 14, 23, 21, 19, 3, 1] [2] Cost: 1605.533 to 1544.628 | Optimized: [1, 7, 13, 9, 15, 6, 20, 1] [3] Cost: 1281.716 to 1256.055 | Optimized: [1, 0, 22, 10, 8, 18, 1] [4] Cost: 1304.255 to 1303.404 | Optimized: [1, 5, 16, 2, 1] ACO RESULTS [1/300 vol./1764.462 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/285 vol./1544.628 km] Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [3/230 vol./1256.055 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/275 vol./1303.404 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5868.549 km.