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
- Düsseldorf Hbf (70 vol.)
- Frankfurt Hbf (90 vol.)
- Hamburg Hbf (30 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (75 vol.)
- Dortmund Hbf (40 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (30 vol.)
- Ulm Hbf (70 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (35 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (70 vol.)
- Würzburg Hbf (45 vol.)
- Osnabrück Hbf (80 vol.)
Tour 1
COST: 1630.81 km
LOAD: 300 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 70 vol.
- Karlsruhe Hbf | 30 vol.
- Mannheim Hbf | 35 vol.
- Würzburg Hbf | 45 vol.
Tour 2
COST: 1338.524 km
LOAD: 275 vol.
- Dortmund Hbf | 40 vol.
- Mainz Hbf | 70 vol.
- Frankfurt Hbf | 90 vol.
- Leipzig Hbf | 75 vol.
Tour 3
COST: 1297.276 km
LOAD: 285 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 70 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 40 vol.
Tour 4
COST: 732.557 km
LOAD: 100 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 70 vol.
LOAD: 300 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 70 vol.
- Karlsruhe Hbf | 30 vol.
- Mannheim Hbf | 35 vol.
- Würzburg Hbf | 45 vol.
LOAD: 275 vol.
- Dortmund Hbf | 40 vol.
- Mainz Hbf | 70 vol.
- Frankfurt Hbf | 90 vol.
- Leipzig Hbf | 75 vol.
LOAD: 285 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 70 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 40 vol.
LOAD: 100 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 70 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: 960 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 70, 90, 0, 0, 0, 0, 30, 80, 40, 75, 40, 40, 30, 70, 95, 35, 70, 70, 45, 0, 80, 0] ITERATION Generation: #1 Best cost: 5876.952 | Path: [1, 2, 16, 12, 22, 1, 11, 13, 20, 3, 17, 1, 8, 18, 10, 14, 19, 1, 15, 9, 1] Best cost: 5608.016 | Path: [1, 3, 19, 17, 14, 15, 1, 11, 13, 20, 16, 12, 1, 8, 18, 10, 22, 2, 1, 9, 1] Best cost: 5384.279 | Path: [1, 17, 14, 3, 19, 20, 8, 1, 11, 13, 9, 15, 1, 22, 12, 2, 16, 1, 18, 10, 1] Best cost: 5377.450 | Path: [1, 17, 14, 3, 19, 20, 8, 1, 11, 13, 9, 15, 1, 12, 2, 16, 22, 1, 18, 10, 1] Best cost: 5344.248 | Path: [1, 14, 17, 19, 3, 20, 8, 1, 11, 13, 9, 15, 1, 12, 2, 16, 22, 1, 18, 10, 1] Best cost: 5158.946 | Path: [1, 20, 13, 9, 15, 14, 17, 1, 11, 19, 3, 12, 1, 10, 22, 2, 16, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 20, 13, 9, 15, 14, 17, 1], [1, 11, 19, 3, 12, 1], [1, 10, 22, 2, 16, 1], [1, 8, 18, 1]] [1] Cost: 1748.658 to 1630.810 | Optimized: [1, 13, 9, 15, 14, 17, 20, 1] [2] Cost: 1361.854 to 1338.524 | Optimized: [1, 12, 19, 3, 11, 1] [3] Cost: 1315.877 to 1297.276 | Optimized: [1, 16, 2, 22, 10, 1] ACO RESULTS [1/300 vol./1630.810 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Würzburg Hbf --> Berlin Hbf [2/275 vol./1338.524 km] Berlin Hbf -> Dortmund Hbf -> Mainz Hbf -> Frankfurt Hbf -> Leipzig Hbf --> Berlin Hbf [3/285 vol./1297.276 km] Berlin Hbf -> Köln Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Bremen Hbf --> Berlin Hbf [4/100 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 4999.167 km.