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: 15 customers
- Kassel-Wilhelmshöhe (90 vol.)
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (50 vol.)
- Hannover Hbf (95 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (50 vol.)
- Dortmund Hbf (100 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (100 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (20 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1049.343 km
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Dortmund Hbf | 100 vol.
- Hannover Hbf | 95 vol.
Tour 2
COST: 2064.769 km
LOAD: 300 vol.
- Mannheim Hbf | 90 vol.
- Saarbrücken Hbf | 20 vol.
- Freiburg Hbf | 45 vol.
- Stuttgart Hbf | 50 vol.
- München Hbf | 50 vol.
- Dresden Hbf | 45 vol.
Tour 3
COST: 1678.547 km
LOAD: 265 vol.
- Würzburg Hbf | 30 vol.
- Frankfurt Hbf | 50 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 35 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 100 vol.
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Dortmund Hbf | 100 vol.
- Hannover Hbf | 95 vol.
LOAD: 300 vol.
- Mannheim Hbf | 90 vol.
- Saarbrücken Hbf | 20 vol.
- Freiburg Hbf | 45 vol.
- Stuttgart Hbf | 50 vol.
- München Hbf | 50 vol.
- Dresden Hbf | 45 vol.
LOAD: 265 vol.
- Würzburg Hbf | 30 vol.
- Frankfurt Hbf | 50 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 35 vol.
- Hamburg Hbf | 20 vol.
- Kiel 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: 850 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 35, 50, 95, 0, 50, 45, 20, 50, 0, 0, 100, 0, 0, 0, 30, 90, 100, 0, 30, 20, 0, 45] ITERATION Generation: #1 Best cost: 5750.585 | Path: [1, 0, 12, 2, 16, 21, 8, 1, 7, 4, 18, 20, 1, 3, 17, 6, 23, 9, 1] Best cost: 5523.247 | Path: [1, 3, 17, 21, 23, 6, 20, 1, 7, 4, 8, 18, 16, 1, 0, 12, 2, 9, 1] Best cost: 5301.782 | Path: [1, 4, 8, 18, 20, 6, 1, 7, 0, 12, 2, 16, 1, 3, 17, 21, 23, 9, 1] Best cost: 5082.239 | Path: [1, 7, 0, 12, 16, 2, 1, 8, 18, 4, 3, 20, 1, 9, 6, 17, 21, 23, 1] Best cost: 5078.177 | Path: [1, 18, 8, 4, 3, 20, 1, 7, 0, 12, 2, 16, 1, 6, 17, 21, 23, 9, 1] Best cost: 4961.846 | Path: [1, 4, 0, 12, 1, 7, 9, 6, 17, 21, 23, 1, 18, 8, 2, 16, 3, 20, 1] OPTIMIZING each tour... Current: [[1, 4, 0, 12, 1], [1, 7, 9, 6, 17, 21, 23, 1], [1, 18, 8, 2, 16, 3, 20, 1]] [1] Cost: 1116.087 to 1049.343 | Optimized: [1, 0, 12, 4, 1] [2] Cost: 2159.080 to 2064.769 | Optimized: [1, 17, 21, 23, 6, 9, 7, 1] [3] Cost: 1686.679 to 1678.547 | Optimized: [1, 20, 3, 16, 2, 8, 18, 1] ACO RESULTS [1/285 vol./1049.343 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Hannover Hbf --> Berlin Hbf [2/300 vol./2064.769 km] Berlin Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Stuttgart Hbf -> München Hbf -> Dresden Hbf --> Berlin Hbf [3/265 vol./1678.547 km] Berlin Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Köln Hbf -> Düsseldorf Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4792.659 km.