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: 18 customers
- Kassel-Wilhelmshöhe (65 vol.)
- Frankfurt Hbf (75 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (100 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (30 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (75 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (20 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (85 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (30 vol.)
- Mainz Hbf (20 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1509.806 km
LOAD: 300 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 100 vol.
- Ulm Hbf | 85 vol.
- Nürnberg Hbf | 20 vol.
Tour 2
COST: 1007.951 km
LOAD: 280 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 75 vol.
- Hannover Hbf | 85 vol.
- Hamburg Hbf | 30 vol.
Tour 3
COST: 1575.197 km
LOAD: 285 vol.
- Dortmund Hbf | 65 vol.
- Aachen Hbf | 100 vol.
- Osnabrück Hbf | 90 vol.
- Kiel Hbf | 30 vol.
Tour 4
COST: 1786.699 km
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Frankfurt Hbf | 75 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 75 vol.
Tour 5
COST: 781.807 km
LOAD: 75 vol.
- Bremen Hbf | 75 vol.
LOAD: 300 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 100 vol.
- Ulm Hbf | 85 vol.
- Nürnberg Hbf | 20 vol.
LOAD: 280 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 75 vol.
- Hannover Hbf | 85 vol.
- Hamburg Hbf | 30 vol.
LOAD: 285 vol.
- Dortmund Hbf | 65 vol.
- Aachen Hbf | 100 vol.
- Osnabrück Hbf | 90 vol.
- Kiel Hbf | 30 vol.
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Frankfurt Hbf | 75 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 75 vol.
LOAD: 75 vol.
- Bremen 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: [1] Berlin Hbf | Number of cities: 24 | Total loads: 1235 vol. | Vehicle capacity: 300 vol. Loads: [65, 0, 0, 75, 85, 100, 0, 90, 30, 0, 75, 75, 65, 20, 100, 85, 0, 75, 30, 20, 0, 80, 90, 75] ITERATION Generation: #1 Best cost: 8299.546 | Path: [1, 0, 22, 12, 3, 1, 11, 7, 4, 8, 19, 1, 18, 10, 5, 21, 1, 13, 14, 17, 23, 1, 15, 1] Best cost: 7998.281 | Path: [1, 3, 19, 17, 14, 13, 1, 11, 7, 0, 12, 1, 8, 18, 4, 10, 21, 1, 22, 5, 23, 1, 15, 1] Best cost: 7644.971 | Path: [1, 5, 12, 22, 8, 1, 11, 7, 13, 15, 19, 1, 4, 10, 18, 0, 1, 17, 14, 3, 1, 21, 23, 1] Best cost: 7375.333 | Path: [1, 7, 11, 13, 15, 19, 1, 8, 18, 10, 4, 0, 1, 22, 12, 5, 1, 3, 17, 14, 1, 21, 23, 1] Best cost: 7185.238 | Path: [1, 13, 3, 19, 17, 14, 1, 7, 11, 4, 8, 1, 10, 22, 12, 0, 1, 18, 5, 21, 23, 1, 15, 1] Best cost: 7148.130 | Path: [1, 19, 3, 17, 14, 13, 1, 11, 7, 4, 8, 1, 18, 22, 12, 0, 1, 15, 23, 21, 1, 10, 5, 1] Best cost: 7087.159 | Path: [1, 12, 5, 21, 19, 13, 1, 7, 11, 4, 8, 1, 18, 10, 22, 0, 1, 17, 14, 3, 1, 15, 23, 1] Best cost: 7085.616 | Path: [1, 15, 14, 17, 19, 13, 1, 11, 7, 4, 8, 1, 18, 10, 22, 12, 1, 0, 3, 21, 23, 1, 5, 1] Best cost: 6978.439 | Path: [1, 13, 15, 14, 17, 19, 1, 11, 7, 4, 8, 1, 18, 10, 22, 12, 1, 0, 3, 21, 23, 1, 5, 1] Best cost: 6964.996 | Path: [1, 15, 14, 17, 19, 13, 1, 7, 11, 10, 8, 18, 1, 4, 22, 12, 1, 0, 3, 21, 23, 1, 5, 1] Best cost: 6879.243 | Path: [1, 13, 15, 14, 17, 19, 1, 7, 11, 4, 8, 1, 18, 10, 22, 12, 1, 0, 3, 21, 23, 1, 5, 1] Generation: #2 Best cost: 6815.239 | Path: [1, 13, 15, 14, 17, 19, 1, 11, 7, 4, 8, 1, 22, 12, 5, 18, 1, 0, 3, 21, 23, 1, 10, 1] OPTIMIZING each tour... Current: [[1, 13, 15, 14, 17, 19, 1], [1, 11, 7, 4, 8, 1], [1, 22, 12, 5, 18, 1], [1, 0, 3, 21, 23, 1], [1, 10, 1]] [1] Cost: 1515.040 to 1509.806 | Optimized: [1, 19, 17, 14, 15, 13, 1] [2] Cost: 1107.147 to 1007.951 | Optimized: [1, 7, 11, 4, 8, 1] [3] Cost: 1624.546 to 1575.197 | Optimized: [1, 12, 5, 22, 18, 1] ACO RESULTS [1/300 vol./1509.806 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Ulm Hbf -> Nürnberg Hbf --> Berlin Hbf [2/280 vol./1007.951 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf [3/285 vol./1575.197 km] Berlin Hbf -> Dortmund Hbf -> Aachen Hbf -> Osnabrück Hbf -> Kiel Hbf --> Berlin Hbf [4/295 vol./1786.699 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Saarbrücken Hbf -> Freiburg Hbf --> Berlin Hbf [5/ 75 vol./ 781.807 km] Berlin Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6661.460 km.