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: 21 customers
- Kassel-Wilhelmshöhe (30 vol.)
- Düsseldorf Hbf (85 vol.)
- Frankfurt Hbf (25 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (95 vol.)
- München Hbf (90 vol.)
- Bremen Hbf (45 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (85 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (85 vol.)
- Mainz Hbf (30 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (85 vol.)
Tour 1
COST: 1531.583 km
LOAD: 300 vol.
- Frankfurt Hbf | 25 vol.
- Mainz Hbf | 30 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 55 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 85 vol.
Tour 2
COST: 1406.736 km
LOAD: 290 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 85 vol.
- Köln Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 30 vol.
- Dresden Hbf | 95 vol.
Tour 3
COST: 972.057 km
LOAD: 250 vol.
- Hannover Hbf | 25 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 85 vol.
Tour 4
COST: 1662.606 km
LOAD: 225 vol.
- Saarbrücken Hbf | 80 vol.
- Aachen Hbf | 60 vol.
- Osnabrück Hbf | 85 vol.
Tour 5
COST: 1345.202 km
LOAD: 265 vol.
- Würzburg Hbf | 95 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 90 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 25 vol.
- Mainz Hbf | 30 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 55 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 85 vol.
LOAD: 290 vol.
- Dortmund Hbf | 20 vol.
- Düsseldorf Hbf | 85 vol.
- Köln Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 30 vol.
- Dresden Hbf | 95 vol.
LOAD: 250 vol.
- Hannover Hbf | 25 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 85 vol.
LOAD: 225 vol.
- Saarbrücken Hbf | 80 vol.
- Aachen Hbf | 60 vol.
- Osnabrück Hbf | 85 vol.
LOAD: 265 vol.
- Würzburg Hbf | 95 vol.
- Nürnberg Hbf | 80 vol.
- München 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: 1330 vol. | Vehicle capacity: 300 vol. Loads: [30, 0, 85, 25, 25, 60, 20, 95, 95, 90, 45, 0, 20, 80, 55, 85, 60, 85, 85, 30, 95, 80, 85, 0] ITERATION Generation: #1 Best cost: 7823.364 | Path: [1, 0, 22, 10, 8, 4, 12, 1, 7, 13, 20, 3, 1, 18, 16, 2, 5, 1, 15, 6, 14, 17, 19, 1, 9, 21, 1] Best cost: 7314.429 | Path: [1, 3, 19, 17, 14, 6, 15, 1, 7, 13, 20, 0, 1, 8, 18, 10, 4, 12, 1, 9, 21, 16, 5, 1, 22, 2, 1] Best cost: 7286.271 | Path: [1, 6, 14, 17, 19, 3, 21, 1, 7, 13, 20, 0, 1, 4, 10, 8, 18, 12, 1, 22, 2, 16, 5, 1, 9, 15, 1] Best cost: 7210.163 | Path: [1, 15, 6, 14, 17, 19, 3, 1, 7, 20, 13, 0, 1, 4, 12, 2, 16, 5, 10, 1, 18, 8, 22, 1, 9, 21, 1] Best cost: 7207.408 | Path: [1, 9, 15, 6, 14, 3, 12, 1, 7, 13, 20, 19, 1, 18, 8, 10, 4, 0, 1, 22, 2, 16, 5, 1, 17, 21, 1] Best cost: 7149.789 | Path: [1, 17, 14, 6, 15, 19, 3, 1, 7, 0, 2, 16, 12, 1, 4, 10, 8, 18, 1, 22, 5, 21, 1, 20, 13, 9, 1] Best cost: 7049.966 | Path: [1, 9, 15, 6, 14, 3, 12, 1, 7, 19, 17, 21, 1, 8, 18, 10, 4, 0, 1, 22, 2, 16, 5, 1, 13, 20, 1] Best cost: 7021.471 | Path: [1, 3, 19, 17, 14, 6, 15, 1, 7, 0, 12, 2, 16, 1, 8, 18, 10, 4, 1, 22, 5, 21, 1, 13, 20, 9, 1] Generation: #2 Best cost: 6953.800 | Path: [1, 6, 14, 17, 19, 3, 16, 12, 1, 7, 13, 20, 0, 1, 4, 10, 8, 18, 1, 22, 2, 5, 1, 9, 15, 21, 1] Generation: #5 Best cost: 6945.416 | Path: [1, 3, 19, 17, 14, 6, 15, 1, 7, 0, 12, 2, 16, 1, 18, 8, 10, 4, 1, 22, 5, 21, 1, 9, 13, 20, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 17, 14, 6, 15, 1], [1, 7, 0, 12, 2, 16, 1], [1, 18, 8, 10, 4, 1], [1, 22, 5, 21, 1], [1, 9, 13, 20, 1]] [2] Cost: 1409.946 to 1406.736 | Optimized: [1, 12, 2, 16, 0, 7, 1] [3] Cost: 981.249 to 972.057 | Optimized: [1, 4, 10, 8, 18, 1] [4] Cost: 1673.161 to 1662.606 | Optimized: [1, 21, 5, 22, 1] [5] Cost: 1349.477 to 1345.202 | Optimized: [1, 20, 13, 9, 1] ACO RESULTS [1/300 vol./1531.583 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [2/290 vol./1406.736 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Kassel-Wilhelmshöhe -> Dresden Hbf --> Berlin Hbf [3/250 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/225 vol./1662.606 km] Berlin Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Osnabrück Hbf --> Berlin Hbf [5/265 vol./1345.202 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6918.184 km.