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: 400 vol.
ACTIVE: 22 customers
- Berlin Hbf (95 vol.)
- Düsseldorf Hbf (50 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (35 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (70 vol.)
- Bremen Hbf (20 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (90 vol.)
- Köln Hbf (25 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (60 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1356.365 km
LOAD: 395 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 65 vol.
- Berlin Hbf | 95 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 100 vol.
Tour 2
COST: 1412.843 km
LOAD: 390 vol.
- Hannover Hbf | 100 vol.
- Bremen Hbf | 20 vol.
- Osnabrück Hbf | 60 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 25 vol.
- Aachen Hbf | 35 vol.
- Saarbrücken Hbf | 60 vol.
- Mannheim Hbf | 20 vol.
Tour 3
COST: 1384.598 km
LOAD: 385 vol.
- Würzburg Hbf | 30 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 70 vol.
- Ulm Hbf | 90 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 65 vol.
Tour 4
COST: 465.535 km
LOAD: 65 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 30 vol.
LOAD: 395 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 65 vol.
- Berlin Hbf | 95 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 100 vol.
LOAD: 390 vol.
- Hannover Hbf | 100 vol.
- Bremen Hbf | 20 vol.
- Osnabrück Hbf | 60 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 25 vol.
- Aachen Hbf | 35 vol.
- Saarbrücken Hbf | 60 vol.
- Mannheim Hbf | 20 vol.
LOAD: 385 vol.
- Würzburg Hbf | 30 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 70 vol.
- Ulm Hbf | 90 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 65 vol.
LOAD: 65 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 30 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1235 vol. | Vehicle capacity: 400 vol. Loads: [0, 95, 50, 30, 100, 35, 0, 35, 100, 70, 20, 100, 20, 65, 65, 90, 25, 20, 65, 35, 30, 60, 60, 65] ITERATION Generation: #1 Best cost: 6599.210 | Path: [0, 1, 11, 7, 20, 3, 19, 17, 16, 12, 0, 4, 10, 22, 2, 5, 15, 0, 14, 23, 21, 13, 9, 18, 0, 8, 0] Best cost: 6015.773 | Path: [0, 2, 16, 5, 12, 22, 10, 8, 18, 17, 0, 4, 11, 7, 1, 13, 0, 19, 3, 20, 14, 15, 9, 21, 0, 23, 0] Best cost: 5782.272 | Path: [0, 3, 19, 17, 14, 23, 15, 9, 12, 0, 11, 7, 1, 4, 10, 2, 0, 22, 8, 18, 5, 16, 21, 20, 0, 13, 0] Best cost: 5512.765 | Path: [0, 4, 10, 8, 18, 1, 12, 0, 22, 2, 16, 5, 19, 3, 17, 14, 23, 0, 20, 13, 9, 15, 21, 7, 0, 11, 0] Best cost: 5432.302 | Path: [0, 8, 18, 10, 22, 12, 2, 16, 5, 17, 0, 20, 13, 15, 14, 23, 21, 0, 3, 19, 11, 7, 1, 4, 0, 9, 0] Best cost: 5266.655 | Path: [0, 10, 4, 22, 12, 2, 16, 5, 19, 3, 17, 0, 20, 13, 9, 15, 14, 23, 0, 8, 18, 11, 7, 1, 0, 21, 0] Best cost: 5248.175 | Path: [0, 10, 8, 18, 4, 22, 12, 16, 0, 2, 5, 19, 3, 17, 14, 23, 21, 20, 0, 13, 9, 15, 7, 11, 0, 1, 0] Best cost: 5200.141 | Path: [0, 3, 19, 17, 14, 23, 21, 2, 16, 5, 0, 12, 22, 10, 8, 18, 4, 7, 0, 20, 13, 9, 15, 11, 0, 1, 0] Best cost: 4953.640 | Path: [0, 11, 7, 1, 18, 8, 0, 22, 10, 4, 12, 2, 16, 5, 19, 3, 17, 0, 20, 13, 9, 15, 14, 23, 0, 21, 0] Best cost: 4904.694 | Path: [0, 4, 10, 22, 12, 2, 16, 5, 19, 3, 17, 0, 20, 13, 9, 15, 14, 23, 0, 11, 7, 1, 8, 18, 0, 21, 0] Generation: #2 Best cost: 4846.027 | Path: [0, 10, 22, 12, 2, 16, 5, 21, 17, 14, 3, 0, 4, 8, 18, 1, 7, 0, 20, 13, 9, 15, 23, 19, 0, 11, 0] Best cost: 4786.538 | Path: [0, 19, 3, 17, 14, 23, 21, 5, 16, 2, 0, 20, 13, 9, 15, 11, 7, 0, 12, 22, 10, 8, 18, 4, 0, 1, 0] Generation: #3 Best cost: 4727.000 | Path: [0, 11, 7, 1, 8, 18, 0, 22, 10, 4, 12, 2, 16, 5, 21, 17, 0, 20, 13, 9, 15, 14, 23, 0, 3, 19, 0] Generation: #4 Best cost: 4655.023 | Path: [0, 11, 7, 1, 8, 18, 0, 4, 10, 22, 12, 2, 16, 5, 21, 17, 0, 20, 13, 9, 15, 14, 23, 0, 3, 19, 0] Generation: #6 Best cost: 4653.909 | Path: [0, 11, 7, 1, 8, 18, 0, 4, 10, 22, 12, 2, 16, 5, 21, 17, 0, 20, 13, 9, 15, 14, 23, 0, 19, 3, 0] OPTIMIZING each tour... Current: [[0, 11, 7, 1, 8, 18, 0], [0, 4, 10, 22, 12, 2, 16, 5, 21, 17, 0], [0, 20, 13, 9, 15, 14, 23, 0], [0, 19, 3, 0]] [1] Cost: 1390.933 to 1356.365 | Optimized: [0, 8, 18, 1, 7, 11, 0] ACO RESULTS [1/395 vol./1356.365 km] Kassel-Wilhelmshöhe -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/390 vol./1412.843 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Osnabrück Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe [3/385 vol./1384.598 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [4/ 65 vol./ 465.535 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4619.341 km.