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
- Frankfurt Hbf (60 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (55 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (30 vol.)
- Karlsruhe Hbf (50 vol.)
- Ulm Hbf (35 vol.)
- Köln Hbf (25 vol.)
- Mannheim Hbf (35 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (35 vol.)
- Osnabrück Hbf (35 vol.)
- Freiburg Hbf (40 vol.)
Tour 1
COST: 1649.944 km
LOAD: 290 vol.
- Mainz Hbf | 20 vol.
- Köln Hbf | 25 vol.
- Dortmund Hbf | 60 vol.
- Osnabrück Hbf | 35 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 65 vol.
Tour 2
COST: 1542.222 km
LOAD: 295 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 35 vol.
- Würzburg Hbf | 95 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 50 vol.
Tour 3
COST: 2005.228 km
LOAD: 290 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 35 vol.
- Freiburg Hbf | 40 vol.
- Saarbrücken Hbf | 35 vol.
- Mannheim Hbf | 35 vol.
- Frankfurt Hbf | 60 vol.
LOAD: 290 vol.
- Mainz Hbf | 20 vol.
- Köln Hbf | 25 vol.
- Dortmund Hbf | 60 vol.
- Osnabrück Hbf | 35 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 65 vol.
LOAD: 295 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 35 vol.
- Würzburg Hbf | 95 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 50 vol.
LOAD: 290 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 35 vol.
- Freiburg Hbf | 40 vol.
- Saarbrücken Hbf | 35 vol.
- Mannheim Hbf | 35 vol.
- Frankfurt Hbf | 60 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: 875 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 0, 60, 0, 0, 30, 85, 85, 55, 0, 35, 60, 30, 50, 35, 25, 35, 65, 20, 95, 35, 35, 40] ITERATION Generation: #1 Best cost: 6452.022 | Path: [1, 3, 19, 17, 14, 6, 15, 9, 1, 11, 7, 13, 20, 23, 1, 8, 18, 22, 12, 16, 1, 21, 1] Best cost: 5741.132 | Path: [1, 6, 14, 17, 21, 23, 3, 19, 16, 1, 7, 11, 13, 20, 15, 1, 8, 18, 22, 12, 9, 1] Best cost: 5554.766 | Path: [1, 7, 11, 13, 20, 19, 17, 1, 8, 18, 22, 12, 16, 6, 1, 3, 14, 21, 23, 15, 9, 1] Best cost: 5455.439 | Path: [1, 7, 11, 13, 20, 19, 17, 1, 8, 18, 22, 12, 16, 6, 1, 9, 15, 14, 23, 21, 3, 1] Best cost: 5335.855 | Path: [1, 8, 18, 22, 12, 16, 19, 1, 11, 7, 9, 15, 6, 14, 1, 13, 20, 3, 17, 21, 23, 1] Best cost: 5267.314 | Path: [1, 7, 11, 20, 13, 9, 1, 8, 18, 22, 12, 16, 19, 1, 3, 17, 14, 6, 15, 23, 21, 1] Generation: #3 Best cost: 5252.224 | Path: [1, 18, 8, 22, 12, 16, 19, 1, 11, 7, 20, 6, 14, 1, 13, 9, 15, 23, 21, 17, 3, 1] OPTIMIZING each tour... Current: [[1, 18, 8, 22, 12, 16, 19, 1], [1, 11, 7, 20, 6, 14, 1], [1, 13, 9, 15, 23, 21, 17, 3, 1]] [1] Cost: 1668.912 to 1649.944 | Optimized: [1, 19, 16, 12, 22, 8, 18, 1] [2] Cost: 1578.084 to 1542.222 | Optimized: [1, 7, 11, 20, 6, 14, 1] ACO RESULTS [1/290 vol./1649.944 km] Berlin Hbf -> Mainz Hbf -> Köln Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [2/295 vol./1542.222 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Würzburg Hbf -> Stuttgart Hbf -> Karlsruhe Hbf --> Berlin Hbf [3/290 vol./2005.228 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mannheim Hbf -> Frankfurt Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 5197.394 km.