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 (65 vol.)
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (50 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (35 vol.)
- Dresden Hbf (30 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (70 vol.)
- Nürnberg Hbf (50 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (90 vol.)
- Mannheim Hbf (60 vol.)
- Kiel Hbf (30 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 2063.021 km
LOAD: 300 vol.
- Mannheim Hbf | 60 vol.
- Karlsruhe Hbf | 45 vol.
- Saarbrücken Hbf | 20 vol.
- Freiburg Hbf | 45 vol.
- Ulm Hbf | 90 vol.
- München Hbf | 40 vol.
Tour 2
COST: 1179.657 km
LOAD: 285 vol.
- Dresden Hbf | 30 vol.
- Leipzig Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Osnabrück Hbf | 70 vol.
- Hannover Hbf | 50 vol.
Tour 3
COST: 1583.036 km
LOAD: 300 vol.
- Kiel Hbf | 30 vol.
- Hamburg Hbf | 80 vol.
- Bremen Hbf | 90 vol.
- Düsseldorf Hbf | 65 vol.
- Aachen Hbf | 35 vol.
Tour 4
COST: 1275.483 km
LOAD: 250 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 50 vol.
- Würzburg Hbf | 50 vol.
- Nürnberg Hbf | 50 vol.
LOAD: 300 vol.
- Mannheim Hbf | 60 vol.
- Karlsruhe Hbf | 45 vol.
- Saarbrücken Hbf | 20 vol.
- Freiburg Hbf | 45 vol.
- Ulm Hbf | 90 vol.
- München Hbf | 40 vol.
LOAD: 285 vol.
- Dresden Hbf | 30 vol.
- Leipzig Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Osnabrück Hbf | 70 vol.
- Hannover Hbf | 50 vol.
LOAD: 300 vol.
- Kiel Hbf | 30 vol.
- Hamburg Hbf | 80 vol.
- Bremen Hbf | 90 vol.
- Düsseldorf Hbf | 65 vol.
- Aachen Hbf | 35 vol.
LOAD: 250 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 50 vol.
- Würzburg Hbf | 50 vol.
- Nürnberg Hbf | 50 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: 1135 vol. | Vehicle capacity: 300 vol. Loads: [65, 0, 65, 50, 50, 35, 0, 30, 80, 40, 90, 70, 0, 50, 45, 90, 0, 60, 30, 100, 50, 20, 70, 45] ITERATION Generation: #1 Best cost: 7738.809 | Path: [1, 0, 4, 10, 22, 21, 1, 7, 11, 17, 19, 5, 1, 8, 18, 2, 3, 14, 1, 13, 20, 15, 9, 23, 1] Best cost: 6639.949 | Path: [1, 2, 5, 22, 10, 18, 1, 11, 7, 13, 20, 3, 14, 1, 8, 4, 0, 19, 1, 17, 21, 23, 15, 9, 1] Best cost: 6372.019 | Path: [1, 7, 11, 0, 22, 4, 1, 8, 18, 10, 2, 5, 1, 20, 13, 9, 15, 14, 21, 1, 3, 19, 17, 23, 1] Best cost: 6300.081 | Path: [1, 17, 14, 23, 21, 19, 7, 1, 11, 4, 10, 8, 1, 18, 22, 2, 5, 20, 13, 1, 0, 3, 15, 9, 1] Best cost: 6279.153 | Path: [1, 21, 17, 14, 23, 3, 20, 7, 1, 11, 4, 10, 8, 1, 18, 22, 2, 5, 19, 1, 13, 9, 15, 0, 1] Best cost: 6177.716 | Path: [1, 17, 14, 23, 21, 19, 7, 1, 11, 13, 20, 0, 4, 1, 8, 18, 10, 22, 1, 2, 5, 3, 15, 9, 1] Generation: #2 Best cost: 6134.027 | Path: [1, 21, 17, 14, 23, 15, 9, 1, 7, 11, 0, 22, 4, 1, 8, 18, 10, 2, 5, 1, 13, 20, 3, 19, 1] OPTIMIZING each tour... Current: [[1, 21, 17, 14, 23, 15, 9, 1], [1, 7, 11, 0, 22, 4, 1], [1, 8, 18, 10, 2, 5, 1], [1, 13, 20, 3, 19, 1]] [1] Cost: 2077.210 to 2063.021 | Optimized: [1, 17, 14, 21, 23, 15, 9, 1] [3] Cost: 1593.865 to 1583.036 | Optimized: [1, 18, 8, 10, 2, 5, 1] [4] Cost: 1283.295 to 1275.483 | Optimized: [1, 19, 3, 20, 13, 1] ACO RESULTS [1/300 vol./2063.021 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Ulm Hbf -> München 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/300 vol./1583.036 km] Berlin Hbf -> Kiel Hbf -> Hamburg Hbf -> Bremen Hbf -> Düsseldorf Hbf -> Aachen Hbf --> Berlin Hbf [4/250 vol./1275.483 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6101.197 km.