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: 16 customers
- Kassel-Wilhelmshöhe (80 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (45 vol.)
- Hamburg Hbf (55 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (60 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (25 vol.)
- Ulm Hbf (35 vol.)
- Köln Hbf (100 vol.)
- Mannheim Hbf (35 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (30 vol.)
- Saarbrücken Hbf (35 vol.)
Tour 1
COST: 1642.951 km
LOAD: 295 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 45 vol.
- Karlsruhe Hbf | 25 vol.
- Mannheim Hbf | 35 vol.
- Mainz Hbf | 30 vol.
Tour 2
COST: 1690.788 km
LOAD: 290 vol.
- Köln Hbf | 100 vol.
- Aachen Hbf | 45 vol.
- Saarbrücken Hbf | 35 vol.
- Frankfurt Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 80 vol.
Tour 3
COST: 972.057 km
LOAD: 235 vol.
- Hannover Hbf | 100 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 55 vol.
- Kiel Hbf | 20 vol.
LOAD: 295 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 45 vol.
- Karlsruhe Hbf | 25 vol.
- Mannheim Hbf | 35 vol.
- Mainz Hbf | 30 vol.
LOAD: 290 vol.
- Köln Hbf | 100 vol.
- Aachen Hbf | 45 vol.
- Saarbrücken Hbf | 35 vol.
- Frankfurt Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 80 vol.
LOAD: 235 vol.
- Hannover Hbf | 100 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 55 vol.
- Kiel Hbf | 20 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: 820 vol. | Vehicle capacity: 300 vol. Loads: [80, 0, 0, 30, 100, 45, 45, 0, 55, 25, 60, 0, 0, 100, 25, 35, 100, 35, 20, 30, 0, 35, 0, 0] ITERATION Generation: #1 Best cost: 5717.333 | Path: [1, 0, 3, 19, 17, 14, 6, 15, 18, 1, 8, 10, 4, 5, 21, 1, 13, 9, 16, 1] Best cost: 5387.219 | Path: [1, 3, 19, 17, 14, 6, 15, 9, 21, 18, 1, 4, 10, 8, 0, 1, 13, 5, 16, 1] Best cost: 5263.656 | Path: [1, 4, 10, 8, 18, 5, 1, 0, 3, 19, 17, 14, 6, 15, 1, 13, 9, 21, 16, 1] Best cost: 5067.639 | Path: [1, 8, 10, 4, 0, 1, 18, 13, 9, 15, 6, 14, 17, 1, 19, 3, 21, 5, 16, 1] Best cost: 5025.552 | Path: [1, 9, 15, 6, 14, 17, 19, 3, 21, 18, 1, 8, 10, 4, 0, 1, 13, 16, 5, 1] Best cost: 4959.182 | Path: [1, 13, 9, 15, 6, 14, 17, 19, 1, 8, 18, 10, 4, 5, 1, 3, 21, 16, 0, 1] Best cost: 4924.397 | Path: [1, 0, 4, 10, 8, 1, 18, 16, 5, 19, 3, 17, 14, 1, 13, 9, 15, 6, 21, 1] Best cost: 4869.958 | Path: [1, 21, 17, 14, 6, 15, 9, 13, 1, 8, 18, 10, 4, 19, 3, 1, 0, 16, 5, 1] Best cost: 4782.479 | Path: [1, 10, 8, 4, 0, 1, 13, 9, 15, 6, 14, 17, 3, 1, 18, 16, 5, 21, 19, 1] Best cost: 4457.035 | Path: [1, 13, 9, 15, 6, 14, 17, 19, 1, 0, 3, 16, 5, 21, 1, 4, 10, 8, 18, 1] Generation: #2 Best cost: 4385.572 | Path: [1, 21, 17, 14, 6, 15, 9, 13, 1, 3, 19, 16, 5, 0, 1, 8, 18, 10, 4, 1] Generation: #4 Best cost: 4374.306 | Path: [1, 0, 16, 5, 21, 17, 1, 13, 9, 15, 6, 14, 3, 19, 1, 4, 10, 8, 18, 1] Generation: #5 Best cost: 4369.331 | Path: [1, 21, 17, 14, 6, 15, 9, 13, 1, 0, 3, 19, 16, 5, 1, 8, 18, 10, 4, 1] Generation: #9 Best cost: 4356.280 | Path: [1, 13, 9, 15, 6, 14, 17, 19, 1, 0, 3, 21, 16, 5, 1, 4, 10, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 13, 9, 15, 6, 14, 17, 19, 1], [1, 0, 3, 21, 16, 5, 1], [1, 4, 10, 8, 18, 1]] [2] Cost: 1741.272 to 1690.788 | Optimized: [1, 16, 5, 21, 3, 0, 1] ACO RESULTS [1/295 vol./1642.951 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Mainz Hbf --> Berlin Hbf [2/290 vol./1690.788 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Frankfurt Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [3/235 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4305.796 km.