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: 18 customers
- Kassel-Wilhelmshöhe (60 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (70 vol.)
- Stuttgart Hbf (40 vol.)
- Dresden Hbf (35 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (60 vol.)
- Leipzig Hbf (65 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (35 vol.)
- Karlsruhe Hbf (20 vol.)
- Köln Hbf (40 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (55 vol.)
- Würzburg Hbf (55 vol.)
- Saarbrücken Hbf (55 vol.)
- Osnabrück Hbf (45 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1440.09 km
LOAD: 295 vol.
- Dortmund Hbf | 85 vol.
- Köln Hbf | 40 vol.
- Frankfurt Hbf | 80 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 35 vol.
Tour 2
COST: 1155.362 km
LOAD: 300 vol.
- Leipzig Hbf | 65 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Osnabrück Hbf | 45 vol.
- Bremen Hbf | 60 vol.
- Hannover Hbf | 70 vol.
Tour 3
COST: 2072.77 km
LOAD: 300 vol.
- Mannheim Hbf | 100 vol.
- Saarbrücken Hbf | 55 vol.
- Freiburg Hbf | 25 vol.
- Karlsruhe Hbf | 20 vol.
- Stuttgart Hbf | 40 vol.
- München Hbf | 25 vol.
- Dresden Hbf | 35 vol.
Tour 4
COST: 701.943 km
LOAD: 55 vol.
- Kiel Hbf | 55 vol.
LOAD: 295 vol.
- Dortmund Hbf | 85 vol.
- Köln Hbf | 40 vol.
- Frankfurt Hbf | 80 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 35 vol.
LOAD: 300 vol.
- Leipzig Hbf | 65 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Osnabrück Hbf | 45 vol.
- Bremen Hbf | 60 vol.
- Hannover Hbf | 70 vol.
LOAD: 300 vol.
- Mannheim Hbf | 100 vol.
- Saarbrücken Hbf | 55 vol.
- Freiburg Hbf | 25 vol.
- Karlsruhe Hbf | 20 vol.
- Stuttgart Hbf | 40 vol.
- München Hbf | 25 vol.
- Dresden Hbf | 35 vol.
LOAD: 55 vol.
- Kiel Hbf | 55 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: 950 vol. | Vehicle capacity: 300 vol. Loads: [60, 0, 0, 80, 70, 0, 40, 35, 0, 25, 60, 65, 85, 35, 20, 0, 40, 100, 55, 0, 55, 55, 45, 25] ITERATION Generation: #1 Best cost: 7302.434 | Path: [1, 0, 4, 10, 22, 16, 14, 1, 11, 7, 13, 20, 3, 23, 1, 18, 12, 17, 21, 1, 9, 6, 1] Best cost: 6185.834 | Path: [1, 3, 17, 14, 6, 20, 1, 11, 7, 13, 9, 23, 21, 16, 1, 4, 22, 10, 18, 0, 1, 12, 1] Best cost: 5772.401 | Path: [1, 6, 14, 17, 3, 20, 1, 11, 7, 13, 9, 21, 23, 0, 1, 4, 10, 22, 12, 16, 1, 18, 1] Best cost: 5509.209 | Path: [1, 12, 16, 3, 20, 13, 1, 4, 10, 22, 0, 11, 1, 7, 6, 14, 17, 21, 23, 9, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 12, 16, 3, 20, 13, 1], [1, 4, 10, 22, 0, 11, 1], [1, 7, 6, 14, 17, 21, 23, 9, 1], [1, 18, 1]] [2] Cost: 1161.029 to 1155.362 | Optimized: [1, 11, 0, 22, 10, 4, 1] [3] Cost: 2206.147 to 2072.770 | Optimized: [1, 17, 21, 23, 14, 6, 9, 7, 1] ACO RESULTS [1/295 vol./1440.090 km] Berlin Hbf -> Dortmund Hbf -> Köln Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf [2/300 vol./1155.362 km] Berlin Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf --> Berlin Hbf [3/300 vol./2072.770 km] Berlin Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> München Hbf -> Dresden Hbf --> Berlin Hbf [4/ 55 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5370.165 km.