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: 15 customers
- Berlin Hbf (90 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (50 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (40 vol.)
- Leipzig Hbf (60 vol.)
- Nürnberg Hbf (95 vol.)
- Karlsruhe Hbf (60 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (90 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (75 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (30 vol.)
Tour 1
COST: 1700.995 km
LOAD: 390 vol.
- Aachen Hbf | 50 vol.
- Osnabrück Hbf | 90 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 80 vol.
- Berlin Hbf | 90 vol.
- Leipzig Hbf | 60 vol.
Tour 2
COST: 1383.794 km
LOAD: 365 vol.
- Würzburg Hbf | 90 vol.
- Nürnberg Hbf | 95 vol.
- München Hbf | 40 vol.
- Stuttgart Hbf | 50 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 30 vol.
Tour 3
COST: 782.306 km
LOAD: 240 vol.
- Mainz Hbf | 90 vol.
- Saarbrücken Hbf | 75 vol.
- Mannheim Hbf | 75 vol.
LOAD: 390 vol.
- Aachen Hbf | 50 vol.
- Osnabrück Hbf | 90 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 80 vol.
- Berlin Hbf | 90 vol.
- Leipzig Hbf | 60 vol.
LOAD: 365 vol.
- Würzburg Hbf | 90 vol.
- Nürnberg Hbf | 95 vol.
- München Hbf | 40 vol.
- Stuttgart Hbf | 50 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 30 vol.
LOAD: 240 vol.
- Mainz Hbf | 90 vol.
- Saarbrücken Hbf | 75 vol.
- Mannheim Hbf | 75 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: 995 vol. | Vehicle capacity: 400 vol. Loads: [0, 90, 0, 0, 0, 50, 50, 0, 20, 40, 0, 60, 0, 95, 60, 0, 0, 75, 80, 90, 90, 75, 90, 30] ITERATION Generation: #1 Best cost: 5022.997 | Path: [0, 1, 11, 13, 20, 6, 0, 22, 5, 19, 17, 14, 23, 0, 8, 18, 21, 9, 0] Best cost: 4904.059 | Path: [0, 5, 21, 17, 14, 6, 20, 0, 22, 19, 13, 9, 23, 8, 0, 11, 1, 18, 0] Best cost: 4833.399 | Path: [0, 6, 14, 17, 19, 21, 23, 8, 0, 22, 5, 20, 13, 9, 0, 11, 1, 18, 0] Best cost: 4286.404 | Path: [0, 8, 18, 1, 11, 13, 9, 0, 22, 5, 19, 17, 14, 23, 0, 20, 6, 21, 0] Best cost: 4155.423 | Path: [0, 5, 22, 8, 18, 1, 11, 0, 20, 13, 9, 14, 17, 23, 0, 19, 21, 6, 0] Best cost: 4127.852 | Path: [0, 22, 8, 18, 1, 11, 6, 0, 19, 17, 14, 23, 21, 5, 0, 20, 13, 9, 0] Best cost: 4122.374 | Path: [0, 11, 1, 8, 18, 22, 5, 0, 20, 13, 9, 6, 17, 23, 0, 19, 14, 21, 0] Best cost: 3925.882 | Path: [0, 11, 1, 18, 8, 22, 5, 0, 20, 13, 9, 6, 14, 23, 0, 19, 17, 21, 0] Best cost: 3903.881 | Path: [0, 5, 22, 8, 18, 1, 11, 0, 20, 13, 9, 6, 14, 23, 0, 19, 17, 21, 0] Generation: #3 Best cost: 3899.925 | Path: [0, 11, 1, 8, 18, 22, 5, 0, 20, 13, 9, 6, 14, 23, 0, 19, 21, 17, 0] OPTIMIZING each tour... Current: [[0, 11, 1, 8, 18, 22, 5, 0], [0, 20, 13, 9, 6, 14, 23, 0], [0, 19, 21, 17, 0]] [1] Cost: 1733.825 to 1700.995 | Optimized: [0, 5, 22, 8, 18, 1, 11, 0] ACO RESULTS [1/390 vol./1700.995 km] Kassel-Wilhelmshöhe -> Aachen Hbf -> Osnabrück Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/365 vol./1383.794 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [3/240 vol./ 782.306 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Saarbrücken Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3867.095 km.