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: 20 customers
- Kassel-Wilhelmshöhe (80 vol.)
- Düsseldorf Hbf (20 vol.)
- Frankfurt Hbf (75 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (75 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (75 vol.)
- Bremen Hbf (80 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (40 vol.)
- Karlsruhe Hbf (75 vol.)
- Köln Hbf (40 vol.)
- Mannheim Hbf (65 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (30 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (40 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1908.281 km
LOAD: 285 vol.
- Frankfurt Hbf | 75 vol.
- Mainz Hbf | 30 vol.
- Saarbrücken Hbf | 20 vol.
- Freiburg Hbf | 25 vol.
- Würzburg Hbf | 30 vol.
- Leipzig Hbf | 20 vol.
- Dresden Hbf | 85 vol.
Tour 2
COST: 1370.534 km
LOAD: 280 vol.
- Dortmund Hbf | 40 vol.
- Düsseldorf Hbf | 20 vol.
- Köln Hbf | 40 vol.
- Aachen Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 80 vol.
Tour 3
COST: 1107.833 km
LOAD: 245 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 25 vol.
Tour 4
COST: 1572.784 km
LOAD: 290 vol.
- München Hbf | 75 vol.
- Stuttgart Hbf | 75 vol.
- Karlsruhe Hbf | 75 vol.
- Mannheim Hbf | 65 vol.
LOAD: 285 vol.
- Frankfurt Hbf | 75 vol.
- Mainz Hbf | 30 vol.
- Saarbrücken Hbf | 20 vol.
- Freiburg Hbf | 25 vol.
- Würzburg Hbf | 30 vol.
- Leipzig Hbf | 20 vol.
- Dresden Hbf | 85 vol.
LOAD: 280 vol.
- Dortmund Hbf | 40 vol.
- Düsseldorf Hbf | 20 vol.
- Köln Hbf | 40 vol.
- Aachen Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 80 vol.
LOAD: 245 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 25 vol.
LOAD: 290 vol.
- München Hbf | 75 vol.
- Stuttgart Hbf | 75 vol.
- Karlsruhe Hbf | 75 vol.
- Mannheim Hbf | 65 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: 1100 vol. | Vehicle capacity: 300 vol. Loads: [80, 0, 20, 75, 0, 100, 75, 85, 100, 75, 80, 20, 40, 0, 75, 0, 40, 65, 25, 30, 30, 20, 40, 25] ITERATION Generation: #1 Best cost: 7691.653 | Path: [1, 0, 12, 2, 16, 5, 21, 1, 11, 7, 20, 3, 19, 23, 18, 1, 22, 10, 8, 14, 1, 6, 17, 9, 1] Best cost: 7020.515 | Path: [1, 2, 16, 5, 12, 22, 18, 11, 1, 7, 9, 6, 17, 1, 10, 8, 0, 19, 1, 20, 3, 14, 23, 21, 1] Best cost: 6888.324 | Path: [1, 9, 6, 14, 17, 1, 7, 11, 20, 3, 19, 21, 22, 1, 8, 18, 10, 12, 2, 23, 1, 0, 16, 5, 1] Best cost: 6544.100 | Path: [1, 18, 8, 10, 22, 12, 1, 7, 11, 0, 19, 3, 1, 6, 14, 17, 21, 23, 20, 1, 2, 16, 5, 9, 1] Best cost: 6520.889 | Path: [1, 0, 22, 10, 8, 1, 11, 7, 20, 3, 19, 21, 23, 1, 18, 12, 2, 16, 5, 17, 1, 9, 6, 14, 1] Best cost: 6467.796 | Path: [1, 18, 8, 10, 22, 12, 1, 11, 7, 0, 3, 19, 1, 2, 16, 5, 21, 17, 23, 20, 1, 6, 14, 9, 1] Best cost: 6441.151 | Path: [1, 6, 14, 17, 19, 21, 23, 1, 11, 7, 9, 20, 3, 1, 8, 18, 10, 22, 12, 1, 2, 16, 5, 0, 1] Best cost: 6235.603 | Path: [1, 7, 11, 20, 3, 19, 21, 23, 1, 8, 18, 10, 22, 12, 1, 0, 2, 16, 5, 1, 9, 6, 14, 17, 1] Best cost: 6164.102 | Path: [1, 19, 3, 17, 14, 23, 21, 1, 11, 7, 20, 6, 9, 1, 8, 18, 10, 22, 12, 1, 0, 2, 16, 5, 1] Best cost: 6141.676 | Path: [1, 3, 19, 17, 14, 23, 21, 1, 11, 7, 20, 6, 9, 1, 8, 18, 10, 22, 12, 1, 0, 2, 16, 5, 1] Generation: #8 Best cost: 6076.647 | Path: [1, 11, 7, 20, 3, 19, 21, 23, 1, 0, 12, 2, 16, 5, 1, 8, 18, 10, 22, 1, 9, 6, 14, 17, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 20, 3, 19, 21, 23, 1], [1, 0, 12, 2, 16, 5, 1], [1, 8, 18, 10, 22, 1], [1, 9, 6, 14, 17, 1]] [1] Cost: 1999.331 to 1908.281 | Optimized: [1, 3, 19, 21, 23, 20, 11, 7, 1] [2] Cost: 1372.044 to 1370.534 | Optimized: [1, 12, 2, 16, 5, 0, 1] [3] Cost: 1132.488 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] ACO RESULTS [1/285 vol./1908.281 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [2/280 vol./1370.534 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [3/245 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/290 vol./1572.784 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5959.432 km.