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: 15 customers
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (20 vol.)
- Hannover Hbf (70 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (100 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (80 vol.)
- Dortmund Hbf (35 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (70 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (95 vol.)
- Mainz Hbf (75 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (40 vol.)
Tour 1
COST: 1570.276 km
LOAD: 295 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 100 vol.
- Frankfurt Hbf | 20 vol.
Tour 2
COST: 1186.092 km
LOAD: 275 vol.
- Dortmund Hbf | 35 vol.
- Osnabrück Hbf | 85 vol.
- Hannover Hbf | 70 vol.
- Hamburg Hbf | 85 vol.
Tour 3
COST: 1660.833 km
LOAD: 270 vol.
- Mainz Hbf | 75 vol.
- Karlsruhe Hbf | 70 vol.
- Freiburg Hbf | 40 vol.
- Nürnberg Hbf | 85 vol.
Tour 4
COST: 1303.404 km
LOAD: 235 vol.
- Aachen Hbf | 60 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 80 vol.
LOAD: 295 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 100 vol.
- Frankfurt Hbf | 20 vol.
LOAD: 275 vol.
- Dortmund Hbf | 35 vol.
- Osnabrück Hbf | 85 vol.
- Hannover Hbf | 70 vol.
- Hamburg Hbf | 85 vol.
LOAD: 270 vol.
- Mainz Hbf | 75 vol.
- Karlsruhe Hbf | 70 vol.
- Freiburg Hbf | 40 vol.
- Nürnberg Hbf | 85 vol.
LOAD: 235 vol.
- Aachen Hbf | 60 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 80 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: 1075 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 80, 20, 70, 60, 100, 0, 85, 80, 0, 0, 35, 85, 70, 95, 95, 0, 0, 75, 0, 0, 85, 40] ITERATION Generation: #1 Best cost: 6714.934 | Path: [1, 2, 16, 5, 12, 3, 1, 4, 22, 8, 23, 1, 13, 9, 15, 1, 19, 6, 14, 1] Best cost: 6194.504 | Path: [1, 3, 19, 14, 6, 12, 1, 8, 4, 22, 5, 1, 13, 9, 15, 23, 1, 2, 16, 1] Best cost: 6033.585 | Path: [1, 8, 4, 22, 12, 3, 1, 13, 9, 15, 23, 1, 19, 14, 6, 1, 2, 16, 5, 1] Best cost: 5854.016 | Path: [1, 6, 14, 23, 19, 1, 8, 4, 22, 12, 3, 1, 13, 9, 15, 1, 16, 2, 5, 1] Best cost: 5844.943 | Path: [1, 9, 15, 6, 3, 1, 8, 4, 22, 12, 1, 13, 19, 14, 23, 1, 2, 16, 5, 1] Best cost: 5838.319 | Path: [1, 15, 6, 14, 3, 1, 8, 4, 22, 12, 1, 13, 9, 23, 19, 1, 5, 16, 2, 1] Best cost: 5754.464 | Path: [1, 9, 15, 6, 3, 1, 8, 4, 22, 12, 1, 13, 14, 23, 19, 1, 16, 2, 5, 1] Generation: #2 Best cost: 5734.939 | Path: [1, 9, 15, 6, 3, 1, 8, 4, 22, 12, 1, 13, 14, 23, 19, 1, 2, 16, 5, 1] Generation: #4 Best cost: 5734.088 | Path: [1, 9, 15, 6, 3, 1, 8, 4, 22, 12, 1, 13, 14, 23, 19, 1, 5, 16, 2, 1] Generation: #5 Best cost: 5731.219 | Path: [1, 9, 15, 6, 3, 1, 8, 4, 22, 12, 1, 19, 14, 23, 13, 1, 2, 16, 5, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 3, 1], [1, 8, 4, 22, 12, 1], [1, 19, 14, 23, 13, 1], [1, 2, 16, 5, 1]] [2] Cost: 1195.855 to 1186.092 | Optimized: [1, 12, 22, 4, 8, 1] [4] Cost: 1304.255 to 1303.404 | Optimized: [1, 5, 16, 2, 1] ACO RESULTS [1/295 vol./1570.276 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Frankfurt Hbf --> Berlin Hbf [2/275 vol./1186.092 km] Berlin Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf [3/270 vol./1660.833 km] Berlin Hbf -> Mainz Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Nürnberg Hbf --> Berlin Hbf [4/235 vol./1303.404 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5720.605 km.