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 (80 vol.)
- Hannover Hbf (30 vol.)
- Aachen Hbf (55 vol.)
- Stuttgart Hbf (100 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (50 vol.)
- Bremen Hbf (40 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (100 vol.)
- Köln Hbf (90 vol.)
- Kiel Hbf (70 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (75 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1773.711 km
LOAD: 285 vol.
- Stuttgart Hbf | 100 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 60 vol.
Tour 2
COST: 1288.403 km
LOAD: 290 vol.
- Frankfurt Hbf | 80 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 100 vol.
- Dresden Hbf | 70 vol.
Tour 3
COST: 1107.833 km
LOAD: 285 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 40 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 70 vol.
Tour 4
COST: 1312.887 km
LOAD: 290 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 90 vol.
- Aachen Hbf | 55 vol.
- Hannover Hbf | 30 vol.
Tour 5
COST: 1459.778 km
LOAD: 70 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- München Hbf | 50 vol.
LOAD: 285 vol.
- Stuttgart Hbf | 100 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 60 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 80 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 100 vol.
- Dresden Hbf | 70 vol.
LOAD: 285 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 40 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 70 vol.
LOAD: 290 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 90 vol.
- Aachen Hbf | 55 vol.
- Hannover Hbf | 30 vol.
LOAD: 70 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- München 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: 1220 vol. | Vehicle capacity: 300 vol. Loads: [20, 0, 50, 80, 30, 55, 100, 70, 100, 50, 40, 0, 65, 100, 100, 0, 90, 0, 70, 0, 40, 60, 75, 25] ITERATION Generation: #1 Best cost: 8145.962 | Path: [1, 0, 3, 20, 13, 9, 1, 7, 4, 10, 22, 12, 1, 8, 18, 2, 5, 23, 1, 16, 21, 14, 1, 6, 1] Best cost: 7826.286 | Path: [1, 2, 16, 5, 12, 0, 1, 7, 4, 10, 22, 18, 1, 8, 13, 20, 21, 1, 9, 6, 14, 23, 1, 3, 1] Best cost: 7523.271 | Path: [1, 9, 6, 14, 23, 0, 1, 7, 13, 20, 3, 1, 4, 10, 22, 12, 2, 1, 8, 18, 16, 1, 21, 5, 1] Best cost: 7517.622 | Path: [1, 18, 8, 10, 4, 0, 20, 1, 7, 13, 3, 2, 1, 22, 12, 16, 5, 1, 14, 6, 23, 21, 1, 9, 1] Best cost: 7194.167 | Path: [1, 23, 21, 14, 6, 1, 7, 13, 20, 3, 1, 0, 12, 2, 16, 5, 1, 8, 18, 10, 22, 1, 4, 9, 1] Best cost: 7129.305 | Path: [1, 12, 2, 16, 5, 4, 1, 7, 13, 20, 3, 1, 22, 10, 8, 18, 1, 0, 6, 14, 23, 9, 1, 21, 1] Best cost: 6975.440 | Path: [1, 6, 14, 23, 21, 1, 7, 13, 20, 3, 1, 8, 18, 10, 22, 1, 4, 12, 2, 16, 5, 1, 0, 9, 1] OPTIMIZING each tour... Current: [[1, 6, 14, 23, 21, 1], [1, 7, 13, 20, 3, 1], [1, 8, 18, 10, 22, 1], [1, 4, 12, 2, 16, 5, 1], [1, 0, 9, 1]] [2] Cost: 1295.031 to 1288.403 | Optimized: [1, 3, 20, 13, 7, 1] [3] Cost: 1132.488 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] [4] Cost: 1314.432 to 1312.887 | Optimized: [1, 12, 2, 16, 5, 4, 1] ACO RESULTS [1/285 vol./1773.711 km] Berlin Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [2/290 vol./1288.403 km] Berlin Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/285 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/290 vol./1312.887 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Hannover Hbf --> Berlin Hbf [5/ 70 vol./1459.778 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> München Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6942.612 km.