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
- Kassel-Wilhelmshöhe (35 vol.)
- Frankfurt Hbf (25 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (30 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (25 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (85 vol.)
- Mainz Hbf (70 vol.)
- Würzburg Hbf (100 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (25 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1329.758 km
LOAD: 280 vol.
- Frankfurt Hbf | 25 vol.
- Mainz Hbf | 70 vol.
- Mannheim Hbf | 85 vol.
- Würzburg Hbf | 100 vol.
Tour 2
COST: 1820.596 km
LOAD: 285 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 25 vol.
- Karlsruhe Hbf | 25 vol.
- Stuttgart Hbf | 30 vol.
- Nürnberg Hbf | 75 vol.
- Leipzig Hbf | 50 vol.
Tour 3
COST: 1412.561 km
LOAD: 265 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Köln Hbf | 55 vol.
- Aachen Hbf | 30 vol.
- Dortmund Hbf | 55 vol.
- Osnabrück Hbf | 25 vol.
- Hannover Hbf | 65 vol.
Tour 4
COST: 781.807 km
LOAD: 90 vol.
- Bremen Hbf | 90 vol.
LOAD: 280 vol.
- Frankfurt Hbf | 25 vol.
- Mainz Hbf | 70 vol.
- Mannheim Hbf | 85 vol.
- Würzburg Hbf | 100 vol.
LOAD: 285 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 25 vol.
- Karlsruhe Hbf | 25 vol.
- Stuttgart Hbf | 30 vol.
- Nürnberg Hbf | 75 vol.
- Leipzig Hbf | 50 vol.
LOAD: 265 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Köln Hbf | 55 vol.
- Aachen Hbf | 30 vol.
- Dortmund Hbf | 55 vol.
- Osnabrück Hbf | 25 vol.
- Hannover Hbf | 65 vol.
LOAD: 90 vol.
- Bremen 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: 920 vol. | Vehicle capacity: 300 vol. Loads: [35, 0, 0, 25, 65, 30, 30, 0, 0, 0, 90, 50, 55, 75, 25, 0, 55, 85, 0, 70, 100, 80, 25, 25] ITERATION Generation: #1 Best cost: 6203.919 | Path: [1, 0, 12, 16, 5, 22, 10, 1, 11, 4, 3, 19, 17, 1, 13, 20, 6, 14, 23, 1, 21, 1] Best cost: 5867.478 | Path: [1, 3, 19, 17, 14, 6, 23, 5, 1, 11, 0, 12, 22, 10, 1, 4, 16, 21, 20, 1, 13, 1] Best cost: 5791.392 | Path: [1, 17, 14, 6, 20, 3, 0, 1, 11, 4, 22, 12, 16, 5, 1, 13, 19, 21, 23, 1, 10, 1] Best cost: 5743.797 | Path: [1, 3, 19, 17, 14, 6, 23, 0, 1, 11, 4, 10, 22, 12, 1, 16, 5, 21, 20, 1, 13, 1] Generation: #2 Best cost: 5739.102 | Path: [1, 11, 4, 10, 22, 12, 1, 0, 3, 19, 17, 14, 6, 23, 1, 16, 5, 21, 20, 1, 13, 1] Generation: #3 Best cost: 5736.157 | Path: [1, 20, 3, 19, 17, 1, 11, 4, 10, 22, 12, 1, 0, 16, 5, 21, 14, 6, 23, 1, 13, 1] Best cost: 5660.443 | Path: [1, 17, 14, 6, 23, 21, 5, 3, 1, 11, 13, 20, 19, 1, 4, 10, 22, 12, 16, 1, 0, 1] Generation: #5 Best cost: 5434.078 | Path: [1, 20, 3, 19, 17, 1, 11, 13, 6, 14, 23, 21, 1, 4, 0, 12, 16, 5, 22, 1, 10, 1] OPTIMIZING each tour... Current: [[1, 20, 3, 19, 17, 1], [1, 11, 13, 6, 14, 23, 21, 1], [1, 4, 0, 12, 16, 5, 22, 1], [1, 10, 1]] [1] Cost: 1347.633 to 1329.758 | Optimized: [1, 3, 19, 17, 20, 1] [2] Cost: 1822.490 to 1820.596 | Optimized: [1, 21, 23, 14, 6, 13, 11, 1] [3] Cost: 1482.148 to 1412.561 | Optimized: [1, 0, 16, 5, 12, 22, 4, 1] ACO RESULTS [1/280 vol./1329.758 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Würzburg Hbf --> Berlin Hbf [2/285 vol./1820.596 km] Berlin Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [3/265 vol./1412.561 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Köln Hbf -> Aachen Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [4/ 90 vol./ 781.807 km] Berlin Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5344.722 km.