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: 17 customers
- Kassel-Wilhelmshöhe (35 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (75 vol.)
- Aachen Hbf (35 vol.)
- Stuttgart Hbf (35 vol.)
- Dresden Hbf (65 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (35 vol.)
- Bremen Hbf (85 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (20 vol.)
- Köln Hbf (100 vol.)
- Kiel Hbf (75 vol.)
- Würzburg Hbf (90 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1219.43 km
LOAD: 300 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 100 vol.
- Osnabrück Hbf | 85 vol.
Tour 2
COST: 1197.302 km
LOAD: 275 vol.
- Dresden Hbf | 65 vol.
- Leipzig Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Hannover Hbf | 75 vol.
- Hamburg Hbf | 20 vol.
Tour 3
COST: 2340.196 km
LOAD: 285 vol.
- München Hbf | 35 vol.
- Stuttgart Hbf | 35 vol.
- Freiburg Hbf | 50 vol.
- Würzburg Hbf | 90 vol.
- Frankfurt Hbf | 40 vol.
- Aachen Hbf | 35 vol.
Tour 4
COST: 944.451 km
LOAD: 160 vol.
- Kiel Hbf | 75 vol.
- Bremen Hbf | 85 vol.
LOAD: 300 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 100 vol.
- Osnabrück Hbf | 85 vol.
LOAD: 275 vol.
- Dresden Hbf | 65 vol.
- Leipzig Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Hannover Hbf | 75 vol.
- Hamburg Hbf | 20 vol.
LOAD: 285 vol.
- München Hbf | 35 vol.
- Stuttgart Hbf | 35 vol.
- Freiburg Hbf | 50 vol.
- Würzburg Hbf | 90 vol.
- Frankfurt Hbf | 40 vol.
- Aachen Hbf | 35 vol.
LOAD: 160 vol.
- Kiel Hbf | 75 vol.
- Bremen Hbf | 85 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: 1020 vol. | Vehicle capacity: 300 vol. Loads: [35, 0, 95, 40, 75, 35, 35, 65, 20, 35, 85, 80, 20, 0, 0, 0, 100, 0, 75, 0, 90, 0, 85, 50] ITERATION Generation: #1 Best cost: 7145.595 | Path: [1, 0, 4, 22, 12, 5, 3, 1, 7, 11, 10, 8, 6, 1, 18, 16, 2, 1, 20, 23, 9, 1] Best cost: 7090.707 | Path: [1, 2, 16, 5, 12, 0, 1, 11, 7, 20, 3, 8, 1, 4, 10, 22, 6, 1, 18, 9, 23, 1] Best cost: 6709.585 | Path: [1, 3, 20, 6, 23, 12, 5, 8, 1, 7, 11, 0, 4, 9, 1, 18, 10, 22, 1, 16, 2, 1] Best cost: 6705.050 | Path: [1, 4, 8, 18, 10, 12, 1, 11, 7, 0, 16, 1, 22, 2, 5, 3, 6, 1, 20, 9, 23, 1] Best cost: 6480.769 | Path: [1, 8, 18, 10, 22, 12, 1, 11, 7, 4, 0, 3, 1, 20, 6, 9, 23, 5, 1, 2, 16, 1] Best cost: 6288.214 | Path: [1, 11, 7, 20, 3, 12, 1, 4, 10, 8, 18, 0, 1, 22, 2, 16, 1, 9, 6, 23, 5, 1] Best cost: 6217.477 | Path: [1, 18, 8, 10, 22, 12, 1, 7, 11, 0, 3, 6, 9, 1, 4, 2, 16, 1, 20, 23, 5, 1] Best cost: 6121.184 | Path: [1, 11, 7, 20, 3, 12, 1, 18, 8, 10, 4, 0, 1, 22, 2, 16, 1, 9, 6, 23, 5, 1] Best cost: 5820.016 | Path: [1, 22, 12, 2, 16, 1, 7, 11, 0, 4, 8, 1, 9, 6, 20, 3, 23, 5, 1, 18, 10, 1] OPTIMIZING each tour... Current: [[1, 22, 12, 2, 16, 1], [1, 7, 11, 0, 4, 8, 1], [1, 9, 6, 20, 3, 23, 5, 1], [1, 18, 10, 1]] [1] Cost: 1226.259 to 1219.430 | Optimized: [1, 12, 2, 16, 22, 1] [3] Cost: 2452.004 to 2340.196 | Optimized: [1, 9, 6, 23, 20, 3, 5, 1] ACO RESULTS [1/300 vol./1219.430 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Osnabrück Hbf --> Berlin Hbf [2/275 vol./1197.302 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf [3/285 vol./2340.196 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Aachen Hbf --> Berlin Hbf [4/160 vol./ 944.451 km] Berlin Hbf -> Kiel Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5701.379 km.