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: 17 customers
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (25 vol.)
- Stuttgart Hbf (60 vol.)
- Hamburg Hbf (25 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (55 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (30 vol.)
- Ulm Hbf (30 vol.)
- Köln Hbf (100 vol.)
- Mannheim Hbf (60 vol.)
- Kiel Hbf (75 vol.)
- Mainz Hbf (75 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1696.382 km
LOAD: 290 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 75 vol.
- Mannheim Hbf | 60 vol.
- Saarbrücken Hbf | 100 vol.
- Aachen Hbf | 25 vol.
Tour 2
COST: 972.057 km
LOAD: 280 vol.
- Hannover Hbf | 85 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 25 vol.
- Kiel Hbf | 75 vol.
Tour 3
COST: 1767.786 km
LOAD: 265 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 60 vol.
- Freiburg Hbf | 90 vol.
- Nürnberg Hbf | 30 vol.
- Leipzig Hbf | 55 vol.
Tour 4
COST: 1208.086 km
LOAD: 215 vol.
- Dortmund Hbf | 65 vol.
- Köln Hbf | 100 vol.
- Osnabrück Hbf | 50 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 75 vol.
- Mannheim Hbf | 60 vol.
- Saarbrücken Hbf | 100 vol.
- Aachen Hbf | 25 vol.
LOAD: 280 vol.
- Hannover Hbf | 85 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 25 vol.
- Kiel Hbf | 75 vol.
LOAD: 265 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 60 vol.
- Freiburg Hbf | 90 vol.
- Nürnberg Hbf | 30 vol.
- Leipzig Hbf | 55 vol.
LOAD: 215 vol.
- Dortmund Hbf | 65 vol.
- Köln Hbf | 100 vol.
- Osnabrück Hbf | 50 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: 1050 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 0, 30, 85, 25, 60, 0, 25, 0, 95, 55, 65, 30, 0, 30, 100, 60, 75, 75, 0, 100, 50, 90] ITERATION Generation: #1 Best cost: 6372.170 | Path: [1, 3, 19, 17, 21, 5, 1, 11, 13, 6, 15, 23, 8, 1, 4, 10, 22, 12, 1, 18, 16, 1] Best cost: 6126.276 | Path: [1, 6, 15, 13, 3, 19, 17, 1, 4, 10, 8, 18, 1, 11, 22, 12, 16, 5, 1, 21, 23, 1] Best cost: 6085.693 | Path: [1, 11, 13, 6, 15, 17, 3, 5, 1, 8, 18, 10, 4, 1, 22, 12, 16, 19, 1, 21, 23, 1] Best cost: 5982.622 | Path: [1, 18, 8, 10, 4, 1, 11, 13, 15, 6, 17, 3, 5, 1, 22, 12, 16, 19, 1, 23, 21, 1] Best cost: 5753.784 | Path: [1, 4, 10, 8, 18, 1, 11, 22, 12, 16, 5, 1, 13, 15, 6, 17, 19, 3, 1, 21, 23, 1] Generation: #2 Best cost: 5653.595 | Path: [1, 3, 19, 17, 21, 5, 1, 4, 10, 8, 18, 1, 11, 13, 15, 6, 23, 1, 22, 12, 16, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 17, 21, 5, 1], [1, 4, 10, 8, 18, 1], [1, 11, 13, 15, 6, 23, 1], [1, 22, 12, 16, 1]] [3] Cost: 1770.241 to 1767.786 | Optimized: [1, 15, 6, 23, 13, 11, 1] [4] Cost: 1214.915 to 1208.086 | Optimized: [1, 12, 16, 22, 1] ACO RESULTS [1/290 vol./1696.382 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf --> Berlin Hbf [2/280 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/265 vol./1767.786 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [4/215 vol./1208.086 km] Berlin Hbf -> Dortmund Hbf -> Köln Hbf -> Osnabrück Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5644.311 km.