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 (35 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (70 vol.)
- Aachen Hbf (85 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (55 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (75 vol.)
- Bremen Hbf (45 vol.)
- Dortmund Hbf (95 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (75 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (30 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (85 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1150.363 km
LOAD: 375 vol.
- Würzburg Hbf | 25 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 75 vol.
- Mannheim Hbf | 30 vol.
Tour 2
COST: 1440.283 km
LOAD: 375 vol.
- Hannover Hbf | 70 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 80 vol.
- Berlin Hbf | 35 vol.
- Dresden Hbf | 55 vol.
Tour 3
COST: 1301.63 km
LOAD: 365 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 85 vol.
- Saarbrücken Hbf | 30 vol.
- Freiburg Hbf | 80 vol.
- Mainz Hbf | 85 vol.
- Frankfurt Hbf | 55 vol.
Tour 4
COST: 584.215 km
LOAD: 255 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 90 vol.
- Osnabrück Hbf | 70 vol.
LOAD: 375 vol.
- Würzburg Hbf | 25 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 75 vol.
- Mannheim Hbf | 30 vol.
LOAD: 375 vol.
- Hannover Hbf | 70 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 80 vol.
- Berlin Hbf | 35 vol.
- Dresden Hbf | 55 vol.
LOAD: 365 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 85 vol.
- Saarbrücken Hbf | 30 vol.
- Freiburg Hbf | 80 vol.
- Mainz Hbf | 85 vol.
- Frankfurt Hbf | 55 vol.
LOAD: 255 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 90 vol.
- Osnabrück Hbf | 70 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: 1370 vol. | Vehicle capacity: 400 vol. Loads: [0, 35, 90, 55, 70, 85, 30, 55, 90, 75, 45, 0, 95, 60, 75, 80, 30, 30, 80, 85, 25, 30, 70, 80] ITERATION Generation: #1 Best cost: 6264.589 | Path: [0, 1, 7, 13, 20, 3, 19, 17, 21, 0, 12, 2, 16, 5, 22, 6, 0, 4, 10, 8, 18, 14, 0, 15, 9, 23, 0] Best cost: 5394.396 | Path: [0, 2, 16, 12, 22, 10, 4, 0, 3, 19, 17, 14, 6, 15, 20, 0, 7, 1, 8, 18, 5, 21, 0, 13, 9, 23, 0] Best cost: 5205.934 | Path: [0, 3, 19, 17, 14, 6, 15, 20, 0, 12, 2, 16, 5, 22, 21, 0, 4, 10, 8, 18, 1, 7, 0, 13, 9, 23, 0] Best cost: 5162.770 | Path: [0, 8, 10, 22, 12, 2, 0, 3, 19, 17, 14, 6, 15, 20, 0, 4, 18, 1, 7, 13, 9, 0, 16, 5, 21, 23, 0] Best cost: 5016.197 | Path: [0, 15, 6, 14, 17, 19, 3, 20, 0, 22, 12, 2, 16, 5, 21, 0, 4, 10, 8, 18, 1, 7, 0, 13, 9, 23, 0] Best cost: 4788.041 | Path: [0, 6, 15, 9, 13, 20, 3, 17, 21, 0, 12, 2, 16, 5, 22, 0, 4, 10, 8, 18, 1, 7, 0, 19, 14, 23, 0] Best cost: 4681.390 | Path: [0, 22, 12, 2, 16, 5, 17, 0, 20, 13, 9, 15, 6, 14, 3, 0, 4, 10, 8, 18, 1, 7, 0, 19, 21, 23, 0] Generation: #4 Best cost: 4587.678 | Path: [0, 17, 14, 6, 15, 9, 13, 20, 0, 4, 10, 8, 18, 1, 7, 0, 3, 19, 21, 23, 5, 16, 0, 12, 2, 22, 0] OPTIMIZING each tour... Current: [[0, 17, 14, 6, 15, 9, 13, 20, 0], [0, 4, 10, 8, 18, 1, 7, 0], [0, 3, 19, 21, 23, 5, 16, 0], [0, 12, 2, 22, 0]] [1] Cost: 1164.618 to 1150.363 | Optimized: [0, 20, 13, 9, 15, 6, 14, 17, 0] [3] Cost: 1398.562 to 1301.630 | Optimized: [0, 16, 5, 21, 23, 19, 3, 0] ACO RESULTS [1/375 vol./1150.363 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe [2/375 vol./1440.283 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf --> Kassel-Wilhelmshöhe [3/365 vol./1301.630 km] Kassel-Wilhelmshöhe -> Köln Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [4/255 vol./ 584.215 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4476.491 km.