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
- Kassel-Wilhelmshöhe (25 vol.)
- Düsseldorf Hbf (100 vol.)
- Aachen Hbf (90 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (30 vol.)
- Hamburg Hbf (95 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (65 vol.)
- Leipzig Hbf (70 vol.)
- Karlsruhe Hbf (40 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (40 vol.)
- Mainz Hbf (30 vol.)
- Würzburg Hbf (40 vol.)
- Osnabrück Hbf (100 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1816.309 km
LOAD: 290 vol.
- Mainz Hbf | 30 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 60 vol.
- Stuttgart Hbf | 70 vol.
- Würzburg Hbf | 40 vol.
- Kassel-Wilhelmshöhe | 25 vol.
Tour 2
COST: 1245.897 km
LOAD: 300 vol.
- Dresden Hbf | 30 vol.
- Leipzig Hbf | 70 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 40 vol.
Tour 3
COST: 1310.724 km
LOAD: 290 vol.
- Aachen Hbf | 90 vol.
- Düsseldorf Hbf | 100 vol.
- Osnabrück Hbf | 100 vol.
Tour 4
COST: 1170.132 km
LOAD: 100 vol.
- München Hbf | 100 vol.
LOAD: 290 vol.
- Mainz Hbf | 30 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 60 vol.
- Stuttgart Hbf | 70 vol.
- Würzburg Hbf | 40 vol.
- Kassel-Wilhelmshöhe | 25 vol.
LOAD: 300 vol.
- Dresden Hbf | 30 vol.
- Leipzig Hbf | 70 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 40 vol.
LOAD: 290 vol.
- Aachen Hbf | 90 vol.
- Düsseldorf Hbf | 100 vol.
- Osnabrück Hbf | 100 vol.
LOAD: 100 vol.
- München Hbf | 100 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: 980 vol. | Vehicle capacity: 300 vol. Loads: [25, 0, 100, 0, 0, 90, 70, 30, 95, 100, 65, 70, 0, 0, 40, 0, 0, 25, 40, 30, 40, 0, 100, 60] ITERATION Generation: #1 Best cost: 6273.379 | Path: [1, 0, 22, 10, 8, 1, 7, 11, 20, 17, 14, 6, 1, 18, 5, 2, 19, 1, 9, 23, 1] Best cost: 6269.780 | Path: [1, 5, 2, 22, 1, 11, 7, 20, 6, 14, 17, 0, 1, 8, 18, 10, 19, 23, 1, 9, 1] Best cost: 6110.980 | Path: [1, 6, 14, 17, 19, 20, 0, 11, 1, 7, 9, 23, 5, 1, 8, 18, 10, 22, 1, 2, 1] Best cost: 6037.298 | Path: [1, 9, 6, 14, 17, 19, 0, 1, 7, 11, 20, 23, 2, 1, 8, 18, 10, 22, 1, 5, 1] Best cost: 5963.660 | Path: [1, 11, 7, 20, 19, 17, 14, 23, 1, 8, 18, 10, 22, 1, 0, 2, 5, 6, 1, 9, 1] Best cost: 5893.795 | Path: [1, 11, 7, 20, 6, 14, 17, 0, 1, 8, 18, 10, 22, 1, 2, 5, 19, 23, 1, 9, 1] Best cost: 5884.365 | Path: [1, 2, 5, 19, 17, 14, 1, 11, 7, 20, 6, 23, 0, 1, 8, 18, 10, 22, 1, 9, 1] Best cost: 5800.840 | Path: [1, 23, 14, 6, 20, 19, 17, 0, 1, 7, 11, 10, 8, 18, 1, 22, 2, 5, 1, 9, 1] Best cost: 5739.455 | Path: [1, 0, 2, 5, 19, 17, 7, 1, 11, 20, 6, 14, 23, 1, 8, 18, 10, 22, 1, 9, 1] Best cost: 5652.578 | Path: [1, 20, 19, 17, 14, 6, 23, 0, 1, 7, 11, 10, 8, 18, 1, 22, 2, 5, 1, 9, 1] OPTIMIZING each tour... Current: [[1, 20, 19, 17, 14, 6, 23, 0, 1], [1, 7, 11, 10, 8, 18, 1], [1, 22, 2, 5, 1], [1, 9, 1]] [1] Cost: 1920.291 to 1816.309 | Optimized: [1, 19, 17, 14, 23, 6, 20, 0, 1] [3] Cost: 1316.258 to 1310.724 | Optimized: [1, 5, 2, 22, 1] ACO RESULTS [1/290 vol./1816.309 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Stuttgart Hbf -> Würzburg Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [2/300 vol./1245.897 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/290 vol./1310.724 km] Berlin Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Osnabrück Hbf --> Berlin Hbf [4/100 vol./1170.132 km] Berlin Hbf -> München Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5543.062 km.