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: 22 customers
- Kassel-Wilhelmshöhe (90 vol.)
- Düsseldorf Hbf (45 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (70 vol.)
- Aachen Hbf (35 vol.)
- Stuttgart Hbf (90 vol.)
- Dresden Hbf (55 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (30 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (30 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (25 vol.)
- Köln Hbf (20 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (60 vol.)
- Mainz Hbf (50 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (45 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (100 vol.)
Tour 1
COST: 1854.477 km
LOAD: 295 vol.
- Mainz Hbf | 50 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 25 vol.
- Saarbrücken Hbf | 45 vol.
- Aachen Hbf | 35 vol.
- Köln Hbf | 20 vol.
- Düsseldorf Hbf | 45 vol.
- Dortmund Hbf | 30 vol.
- Osnabrück Hbf | 20 vol.
Tour 2
COST: 1351.104 km
LOAD: 285 vol.
- Dresden Hbf | 55 vol.
- Leipzig Hbf | 100 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 30 vol.
Tour 3
COST: 972.057 km
LOAD: 260 vol.
- Hannover Hbf | 70 vol.
- Bremen Hbf | 40 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 60 vol.
Tour 4
COST: 1190.918 km
LOAD: 255 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Frankfurt Hbf | 80 vol.
- Würzburg Hbf | 85 vol.
Tour 5
COST: 1638.079 km
LOAD: 190 vol.
- Stuttgart Hbf | 90 vol.
- Freiburg Hbf | 100 vol.
LOAD: 295 vol.
- Mainz Hbf | 50 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 25 vol.
- Saarbrücken Hbf | 45 vol.
- Aachen Hbf | 35 vol.
- Köln Hbf | 20 vol.
- Düsseldorf Hbf | 45 vol.
- Dortmund Hbf | 30 vol.
- Osnabrück Hbf | 20 vol.
LOAD: 285 vol.
- Dresden Hbf | 55 vol.
- Leipzig Hbf | 100 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 30 vol.
LOAD: 260 vol.
- Hannover Hbf | 70 vol.
- Bremen Hbf | 40 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 60 vol.
LOAD: 255 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Frankfurt Hbf | 80 vol.
- Würzburg Hbf | 85 vol.
LOAD: 190 vol.
- Stuttgart Hbf | 90 vol.
- Freiburg Hbf | 100 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: 1285 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 45, 80, 70, 35, 90, 55, 90, 30, 40, 100, 30, 100, 25, 0, 20, 25, 60, 50, 85, 45, 20, 100] ITERATION Generation: #1 Best cost: 7835.773 | Path: [1, 0, 12, 2, 16, 5, 17, 14, 9, 1, 11, 7, 13, 21, 1, 8, 18, 4, 10, 22, 1, 20, 3, 19, 1, 6, 23, 1] Best cost: 7831.429 | Path: [1, 6, 14, 17, 19, 3, 16, 1, 11, 7, 13, 9, 1, 10, 8, 18, 4, 22, 1, 12, 2, 5, 0, 20, 1, 21, 23, 1] Best cost: 7614.418 | Path: [1, 7, 11, 4, 10, 22, 1, 8, 18, 12, 2, 16, 5, 1, 0, 19, 3, 17, 14, 9, 1, 13, 20, 6, 1, 21, 23, 1] Best cost: 7545.784 | Path: [1, 21, 14, 17, 19, 3, 16, 2, 1, 11, 7, 13, 9, 1, 8, 18, 10, 22, 4, 1, 0, 12, 5, 20, 1, 6, 23, 1] Best cost: 7362.608 | Path: [1, 11, 7, 13, 9, 1, 4, 22, 12, 2, 16, 5, 3, 1, 8, 18, 10, 0, 1, 20, 6, 14, 17, 19, 1, 21, 23, 1] Best cost: 7257.612 | Path: [1, 12, 2, 16, 5, 19, 3, 17, 1, 7, 11, 13, 9, 1, 4, 22, 10, 8, 18, 1, 20, 6, 14, 23, 1, 0, 21, 1] Best cost: 7247.264 | Path: [1, 0, 22, 10, 8, 18, 1, 11, 7, 13, 9, 1, 4, 12, 2, 16, 5, 21, 17, 14, 1, 20, 6, 23, 1, 3, 19, 1] Generation: #2 Best cost: 7088.979 | Path: [1, 22, 12, 2, 16, 5, 21, 17, 14, 19, 1, 11, 7, 13, 9, 1, 4, 10, 8, 18, 1, 0, 3, 20, 1, 6, 23, 1] Generation: #3 Best cost: 7087.854 | Path: [1, 22, 12, 2, 16, 5, 21, 23, 1, 11, 7, 13, 9, 1, 0, 3, 19, 17, 14, 1, 8, 18, 10, 4, 1, 20, 6, 1] Best cost: 7039.476 | Path: [1, 22, 12, 2, 16, 5, 21, 14, 17, 19, 1, 11, 7, 13, 9, 1, 4, 10, 8, 18, 1, 0, 3, 20, 1, 6, 23, 1] OPTIMIZING each tour... Current: [[1, 22, 12, 2, 16, 5, 21, 14, 17, 19, 1], [1, 11, 7, 13, 9, 1], [1, 4, 10, 8, 18, 1], [1, 0, 3, 20, 1], [1, 6, 23, 1]] [1] Cost: 1861.096 to 1854.477 | Optimized: [1, 19, 17, 14, 21, 5, 16, 2, 12, 22, 1] [2] Cost: 1377.326 to 1351.104 | Optimized: [1, 7, 11, 13, 9, 1] ACO RESULTS [1/295 vol./1854.477 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Berlin Hbf [2/285 vol./1351.104 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf [3/260 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/255 vol./1190.918 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Würzburg Hbf --> Berlin Hbf [5/190 vol./1638.079 km] Berlin Hbf -> Stuttgart Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7006.635 km.