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: 17 customers
- Kassel-Wilhelmshöhe (85 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (55 vol.)
- Dresden Hbf (95 vol.)
- München Hbf (85 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (80 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (20 vol.)
- Köln Hbf (100 vol.)
- Mainz Hbf (65 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (75 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1748.474 km
LOAD: 285 vol.
- Würzburg Hbf | 50 vol.
- Karlsruhe Hbf | 20 vol.
- Freiburg Hbf | 20 vol.
- Saarbrücken Hbf | 100 vol.
- Mainz Hbf | 65 vol.
- Frankfurt Hbf | 30 vol.
Tour 2
COST: 1030.849 km
LOAD: 260 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 80 vol.
- Nürnberg Hbf | 85 vol.
Tour 3
COST: 1422.44 km
LOAD: 285 vol.
- Aachen Hbf | 55 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 100 vol.
- Hannover Hbf | 55 vol.
Tour 4
COST: 1225.78 km
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 85 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 100 vol.
Tour 5
COST: 1170.132 km
LOAD: 85 vol.
- München Hbf | 85 vol.
LOAD: 285 vol.
- Würzburg Hbf | 50 vol.
- Karlsruhe Hbf | 20 vol.
- Freiburg Hbf | 20 vol.
- Saarbrücken Hbf | 100 vol.
- Mainz Hbf | 65 vol.
- Frankfurt Hbf | 30 vol.
LOAD: 260 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 80 vol.
- Nürnberg Hbf | 85 vol.
LOAD: 285 vol.
- Aachen Hbf | 55 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 100 vol.
- Hannover Hbf | 55 vol.
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 85 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 100 vol.
LOAD: 85 vol.
- München Hbf | 85 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: 1195 vol. | Vehicle capacity: 300 vol. Loads: [85, 0, 95, 30, 55, 55, 0, 95, 0, 85, 100, 80, 0, 85, 20, 0, 100, 0, 0, 65, 50, 100, 75, 20] ITERATION Generation: #1 Best cost: 7769.447 | Path: [1, 0, 20, 13, 14, 23, 3, 1, 11, 7, 22, 1, 4, 10, 16, 1, 2, 5, 19, 9, 1, 21, 1] Best cost: 7454.171 | Path: [1, 3, 19, 14, 21, 23, 20, 1, 11, 7, 4, 5, 1, 10, 22, 2, 1, 0, 16, 13, 1, 9, 1] Best cost: 7328.220 | Path: [1, 4, 10, 22, 5, 1, 11, 7, 13, 14, 23, 1, 19, 3, 20, 0, 1, 2, 16, 21, 1, 9, 1] Best cost: 7122.912 | Path: [1, 10, 22, 4, 3, 14, 23, 1, 7, 11, 0, 1, 13, 20, 19, 21, 1, 16, 2, 5, 1, 9, 1] Best cost: 6871.903 | Path: [1, 20, 3, 19, 16, 5, 1, 7, 11, 13, 14, 23, 1, 4, 0, 22, 9, 1, 10, 2, 21, 1] Best cost: 6829.163 | Path: [1, 21, 14, 23, 3, 19, 20, 1, 11, 7, 13, 1, 4, 10, 22, 5, 1, 0, 2, 16, 1, 9, 1] Best cost: 6800.151 | Path: [1, 3, 19, 14, 23, 21, 5, 1, 11, 7, 13, 1, 4, 10, 22, 20, 1, 0, 2, 16, 1, 9, 1] Best cost: 6735.896 | Path: [1, 20, 3, 19, 14, 23, 21, 1, 11, 7, 13, 1, 4, 10, 22, 5, 1, 0, 2, 16, 1, 9, 1] Best cost: 6701.238 | Path: [1, 3, 19, 21, 14, 23, 20, 1, 11, 7, 13, 1, 4, 10, 22, 5, 1, 16, 2, 0, 1, 9, 1] Best cost: 6700.209 | Path: [1, 3, 19, 21, 14, 23, 20, 1, 11, 7, 13, 1, 4, 10, 22, 5, 1, 0, 2, 16, 1, 9, 1] Best cost: 6673.987 | Path: [1, 3, 19, 21, 14, 23, 20, 1, 7, 11, 13, 1, 4, 10, 22, 5, 1, 0, 2, 16, 1, 9, 1] Generation: #4 Best cost: 6665.636 | Path: [1, 14, 23, 21, 19, 3, 20, 1, 7, 11, 13, 1, 4, 10, 22, 5, 1, 0, 16, 2, 1, 9, 1] Best cost: 6636.975 | Path: [1, 3, 19, 21, 23, 14, 20, 1, 11, 7, 13, 1, 4, 10, 22, 5, 1, 0, 2, 16, 1, 9, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 21, 23, 14, 20, 1], [1, 11, 7, 13, 1], [1, 4, 10, 22, 5, 1], [1, 0, 2, 16, 1], [1, 9, 1]] [1] Cost: 1750.323 to 1748.474 | Optimized: [1, 20, 14, 23, 21, 19, 3, 1] [2] Cost: 1057.071 to 1030.849 | Optimized: [1, 7, 11, 13, 1] [3] Cost: 1433.669 to 1422.440 | Optimized: [1, 5, 22, 10, 4, 1] ACO RESULTS [1/285 vol./1748.474 km] Berlin Hbf -> Würzburg Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/260 vol./1030.849 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf --> Berlin Hbf [3/285 vol./1422.440 km] Berlin Hbf -> Aachen Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf --> Berlin Hbf [4/280 vol./1225.780 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Düsseldorf Hbf -> Köln Hbf --> Berlin Hbf [5/ 85 vol./1170.132 km] Berlin Hbf -> München Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6597.675 km.