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: 19 customers
- Kassel-Wilhelmshöhe (40 vol.)
- Düsseldorf Hbf (100 vol.)
- Frankfurt Hbf (85 vol.)
- Aachen Hbf (60 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (20 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (95 vol.)
- Nürnberg Hbf (80 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (80 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1329.758 km
LOAD: 290 vol.
- Frankfurt Hbf | 85 vol.
- Mainz Hbf | 80 vol.
- Mannheim Hbf | 100 vol.
- Würzburg Hbf | 25 vol.
Tour 2
COST: 1190.175 km
LOAD: 300 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Hamburg Hbf | 65 vol.
Tour 3
COST: 2047.545 km
LOAD: 245 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 20 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 50 vol.
- Köln Hbf | 70 vol.
Tour 4
COST: 1095.698 km
LOAD: 260 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 75 vol.
- Kiel Hbf | 100 vol.
Tour 5
COST: 1272.297 km
LOAD: 255 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 100 vol.
- Aachen Hbf | 60 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 85 vol.
- Mainz Hbf | 80 vol.
- Mannheim Hbf | 100 vol.
- Würzburg Hbf | 25 vol.
LOAD: 300 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Hamburg Hbf | 65 vol.
LOAD: 245 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 20 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 50 vol.
- Köln Hbf | 70 vol.
LOAD: 260 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 75 vol.
- Kiel Hbf | 100 vol.
LOAD: 255 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 100 vol.
- Aachen Hbf | 60 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: 1350 vol. | Vehicle capacity: 300 vol. Loads: [40, 0, 100, 85, 0, 60, 0, 95, 65, 20, 75, 100, 95, 80, 0, 0, 70, 100, 100, 80, 25, 50, 85, 25] ITERATION Generation: #1 Best cost: 8023.768 | Path: [1, 0, 12, 2, 5, 1, 11, 7, 13, 20, 1, 10, 8, 18, 23, 9, 1, 22, 16, 3, 21, 1, 19, 17, 1] Best cost: 7499.150 | Path: [1, 2, 16, 5, 21, 9, 1, 7, 11, 0, 20, 23, 1, 8, 18, 10, 1, 22, 12, 19, 1, 13, 17, 3, 1] Best cost: 7249.110 | Path: [1, 20, 13, 9, 17, 21, 23, 1, 7, 11, 0, 5, 1, 8, 18, 10, 1, 22, 12, 2, 1, 3, 19, 16, 1] Best cost: 7098.177 | Path: [1, 17, 3, 19, 20, 1, 7, 11, 9, 13, 1, 8, 18, 10, 0, 1, 22, 12, 2, 1, 16, 5, 21, 23, 1] Best cost: 7097.996 | Path: [1, 19, 3, 17, 20, 1, 11, 7, 13, 9, 1, 8, 18, 10, 0, 1, 22, 12, 2, 1, 16, 5, 21, 23, 1] Best cost: 7097.887 | Path: [1, 17, 3, 19, 20, 1, 7, 11, 13, 9, 1, 8, 18, 10, 0, 1, 22, 12, 2, 1, 16, 5, 21, 23, 1] Best cost: 7075.570 | Path: [1, 3, 19, 17, 20, 1, 11, 7, 13, 9, 1, 8, 18, 10, 0, 1, 22, 12, 2, 1, 16, 5, 21, 23, 1] Best cost: 7062.671 | Path: [1, 17, 19, 3, 20, 1, 7, 11, 13, 9, 1, 8, 18, 10, 0, 1, 22, 12, 2, 1, 16, 5, 21, 23, 1] Best cost: 7049.348 | Path: [1, 3, 19, 17, 20, 1, 7, 11, 13, 9, 1, 8, 18, 10, 0, 1, 22, 12, 2, 1, 16, 5, 21, 23, 1] Generation: #2 Best cost: 6959.524 | Path: [1, 20, 3, 19, 17, 1, 7, 11, 0, 8, 1, 13, 9, 23, 21, 16, 1, 18, 10, 22, 1, 12, 2, 5, 1] OPTIMIZING each tour... Current: [[1, 20, 3, 19, 17, 1], [1, 7, 11, 0, 8, 1], [1, 13, 9, 23, 21, 16, 1], [1, 18, 10, 22, 1], [1, 12, 2, 5, 1]] [1] Cost: 1347.633 to 1329.758 | Optimized: [1, 3, 19, 17, 20, 1] [4] Cost: 1101.874 to 1095.698 | Optimized: [1, 22, 10, 18, 1] ACO RESULTS [1/290 vol./1329.758 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Würzburg Hbf --> Berlin Hbf [2/300 vol./1190.175 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Hamburg Hbf --> Berlin Hbf [3/245 vol./2047.545 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Köln Hbf --> Berlin Hbf [4/260 vol./1095.698 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [5/255 vol./1272.297 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6935.473 km.