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 (20 vol.)
- Düsseldorf Hbf (50 vol.)
- Frankfurt Hbf (75 vol.)
- Hannover Hbf (75 vol.)
- Aachen Hbf (80 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (55 vol.)
- Bremen Hbf (70 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (60 vol.)
- Karlsruhe Hbf (95 vol.)
- Köln Hbf (85 vol.)
- Mannheim Hbf (50 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (35 vol.)
- Osnabrück Hbf (40 vol.)
Tour 1
COST: 1465.031 km
LOAD: 300 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 100 vol.
- Würzburg Hbf | 30 vol.
- Frankfurt Hbf | 75 vol.
- Mannheim Hbf | 50 vol.
Tour 2
COST: 947.647 km
LOAD: 285 vol.
- Hannover Hbf | 75 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 100 vol.
Tour 3
COST: 1779.565 km
LOAD: 300 vol.
- München Hbf | 55 vol.
- Karlsruhe Hbf | 95 vol.
- Saarbrücken Hbf | 35 vol.
- Mainz Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 20 vol.
Tour 4
COST: 1308.428 km
LOAD: 275 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 85 vol.
- Aachen Hbf | 80 vol.
Tour 5
COST: 701.943 km
LOAD: 95 vol.
- Kiel Hbf | 95 vol.
LOAD: 300 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 100 vol.
- Würzburg Hbf | 30 vol.
- Frankfurt Hbf | 75 vol.
- Mannheim Hbf | 50 vol.
LOAD: 285 vol.
- Hannover Hbf | 75 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 100 vol.
LOAD: 300 vol.
- München Hbf | 55 vol.
- Karlsruhe Hbf | 95 vol.
- Saarbrücken Hbf | 35 vol.
- Mainz Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 20 vol.
LOAD: 275 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 85 vol.
- Aachen Hbf | 80 vol.
LOAD: 95 vol.
- Kiel Hbf | 95 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: 1255 vol. | Vehicle capacity: 300 vol. Loads: [20, 0, 50, 75, 75, 80, 0, 45, 100, 55, 70, 100, 60, 0, 95, 0, 85, 50, 95, 95, 30, 35, 40, 0] ITERATION Generation: #1 Best cost: 7602.843 | Path: [1, 0, 12, 2, 16, 5, 1, 11, 7, 4, 10, 1, 8, 18, 22, 20, 21, 1, 3, 19, 17, 9, 1, 14, 1] Best cost: 7392.836 | Path: [1, 2, 16, 5, 12, 0, 1, 7, 11, 4, 10, 1, 8, 18, 22, 17, 1, 20, 3, 19, 14, 1, 9, 21, 1] Best cost: 7207.420 | Path: [1, 7, 11, 4, 10, 1, 8, 18, 22, 12, 1, 0, 3, 19, 17, 21, 1, 9, 14, 20, 2, 1, 16, 5, 1] Best cost: 7187.185 | Path: [1, 9, 14, 17, 19, 1, 11, 7, 0, 22, 10, 1, 8, 18, 4, 20, 1, 12, 2, 16, 5, 1, 3, 21, 1] Best cost: 7171.745 | Path: [1, 20, 3, 19, 17, 21, 1, 7, 11, 0, 12, 2, 1, 22, 10, 8, 4, 1, 18, 16, 5, 1, 14, 9, 1] Best cost: 7158.206 | Path: [1, 4, 8, 18, 0, 1, 11, 7, 20, 3, 17, 1, 10, 22, 12, 2, 5, 1, 9, 14, 21, 19, 1, 16, 1] Best cost: 6825.101 | Path: [1, 20, 3, 19, 17, 21, 1, 7, 11, 0, 12, 2, 1, 8, 18, 10, 1, 4, 22, 16, 5, 1, 14, 9, 1] Best cost: 6672.596 | Path: [1, 20, 3, 19, 17, 21, 1, 11, 7, 0, 22, 10, 1, 4, 8, 18, 1, 12, 2, 16, 5, 1, 9, 14, 1] Best cost: 6656.058 | Path: [1, 21, 14, 17, 3, 20, 1, 7, 11, 0, 22, 4, 1, 8, 18, 10, 1, 12, 2, 16, 5, 1, 9, 19, 1] Best cost: 6593.029 | Path: [1, 19, 3, 17, 21, 20, 1, 7, 11, 0, 22, 10, 1, 4, 8, 18, 1, 12, 2, 16, 5, 1, 9, 14, 1] Generation: #4 Best cost: 6544.001 | Path: [1, 9, 14, 17, 19, 1, 11, 7, 20, 3, 21, 1, 4, 10, 8, 22, 1, 0, 12, 2, 16, 5, 1, 18, 1] Generation: #7 Best cost: 6490.527 | Path: [1, 11, 7, 20, 3, 17, 1, 4, 10, 8, 22, 1, 0, 12, 2, 16, 5, 1, 19, 21, 14, 9, 1, 18, 1] Generation: #8 Best cost: 6466.139 | Path: [1, 11, 7, 20, 3, 17, 1, 4, 10, 8, 22, 1, 9, 14, 21, 19, 0, 1, 12, 2, 16, 5, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 20, 3, 17, 1], [1, 4, 10, 8, 22, 1], [1, 9, 14, 21, 19, 0, 1], [1, 12, 2, 16, 5, 1], [1, 18, 1]] [1] Cost: 1500.893 to 1465.031 | Optimized: [1, 7, 11, 20, 3, 17, 1] [2] Cost: 1175.310 to 947.647 | Optimized: [1, 4, 22, 10, 8, 1] ACO RESULTS [1/300 vol./1465.031 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Mannheim Hbf --> Berlin Hbf [2/285 vol./ 947.647 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/300 vol./1779.565 km] Berlin Hbf -> München Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/275 vol./1308.428 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf [5/ 95 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6202.614 km.