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 (60 vol.)
- Düsseldorf Hbf (60 vol.)
- Hannover Hbf (90 vol.)
- Stuttgart Hbf (55 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (60 vol.)
- Bremen Hbf (95 vol.)
- Dortmund Hbf (95 vol.)
- Nürnberg Hbf (80 vol.)
- Köln Hbf (85 vol.)
- Mannheim Hbf (95 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (90 vol.)
- Würzburg Hbf (95 vol.)
- Osnabrück Hbf (35 vol.)
Tour 1
COST: 1231.292 km
LOAD: 300 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 60 vol.
Tour 2
COST: 1347.336 km
LOAD: 275 vol.
- Würzburg Hbf | 95 vol.
- Stuttgart Hbf | 55 vol.
- Nürnberg Hbf | 80 vol.
- Dresden Hbf | 45 vol.
Tour 3
COST: 1107.833 km
LOAD: 280 vol.
- Osnabrück Hbf | 35 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 90 vol.
Tour 4
COST: 1362.933 km
LOAD: 275 vol.
- Mannheim Hbf | 95 vol.
- Mainz Hbf | 90 vol.
- Hannover Hbf | 90 vol.
LOAD: 300 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 60 vol.
LOAD: 275 vol.
- Würzburg Hbf | 95 vol.
- Stuttgart Hbf | 55 vol.
- Nürnberg Hbf | 80 vol.
- Dresden Hbf | 45 vol.
LOAD: 280 vol.
- Osnabrück Hbf | 35 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 90 vol.
LOAD: 275 vol.
- Mannheim Hbf | 95 vol.
- Mainz Hbf | 90 vol.
- Hannover Hbf | 90 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: 1130 vol. | Vehicle capacity: 300 vol. Loads: [60, 0, 60, 0, 90, 0, 55, 45, 60, 0, 95, 0, 95, 80, 0, 0, 85, 95, 90, 90, 95, 0, 35, 0] ITERATION Generation: #1 Best cost: 6660.470 | Path: [1, 0, 4, 10, 22, 1, 7, 19, 17, 6, 1, 18, 8, 12, 1, 13, 20, 2, 1, 16, 1] Best cost: 5556.905 | Path: [1, 2, 16, 12, 22, 1, 7, 13, 20, 6, 1, 4, 8, 18, 0, 1, 10, 17, 19, 1] Best cost: 5436.924 | Path: [1, 7, 13, 20, 6, 1, 4, 10, 22, 0, 1, 8, 18, 2, 16, 1, 17, 19, 12, 1] Best cost: 5353.548 | Path: [1, 10, 8, 18, 22, 1, 7, 13, 20, 6, 1, 0, 12, 2, 16, 1, 4, 19, 17, 1] Best cost: 5273.691 | Path: [1, 6, 17, 19, 0, 1, 7, 13, 20, 2, 1, 8, 18, 10, 22, 1, 4, 12, 16, 1] Best cost: 5132.841 | Path: [1, 0, 12, 2, 16, 1, 7, 13, 20, 6, 1, 8, 18, 10, 22, 1, 4, 17, 19, 1] Best cost: 5131.331 | Path: [1, 12, 2, 16, 0, 1, 8, 18, 10, 22, 1, 7, 13, 20, 6, 1, 4, 17, 19, 1] Generation: #2 Best cost: 5122.737 | Path: [1, 0, 12, 2, 16, 1, 7, 13, 20, 6, 1, 18, 8, 10, 22, 1, 4, 19, 17, 1] Generation: #3 Best cost: 5122.012 | Path: [1, 0, 12, 2, 16, 1, 7, 13, 20, 6, 1, 18, 8, 10, 22, 1, 4, 17, 19, 1] OPTIMIZING each tour... Current: [[1, 0, 12, 2, 16, 1], [1, 7, 13, 20, 6, 1], [1, 18, 8, 10, 22, 1], [1, 4, 17, 19, 1]] [1] Cost: 1232.802 to 1231.292 | Optimized: [1, 12, 2, 16, 0, 1] [2] Cost: 1404.199 to 1347.336 | Optimized: [1, 20, 6, 13, 7, 1] [3] Cost: 1121.659 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] [4] Cost: 1363.352 to 1362.933 | Optimized: [1, 17, 19, 4, 1] ACO RESULTS [1/300 vol./1231.292 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [2/275 vol./1347.336 km] Berlin Hbf -> Würzburg Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/280 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/275 vol./1362.933 km] Berlin Hbf -> Mannheim Hbf -> Mainz Hbf -> Hannover Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5049.394 km.