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 (70 vol.)
- Düsseldorf Hbf (45 vol.)
- Stuttgart Hbf (80 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (70 vol.)
- Karlsruhe Hbf (80 vol.)
- Mannheim Hbf (60 vol.)
- Kiel Hbf (40 vol.)
- Mainz Hbf (80 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (85 vol.)
Tour 1
COST: 1367.158 km
LOAD: 280 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Leipzig Hbf | 20 vol.
- Dresden Hbf | 75 vol.
Tour 2
COST: 1572.784 km
LOAD: 280 vol.
- München Hbf | 60 vol.
- Stuttgart Hbf | 80 vol.
- Karlsruhe Hbf | 80 vol.
- Mannheim Hbf | 60 vol.
Tour 3
COST: 1107.833 km
LOAD: 235 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 40 vol.
Tour 4
COST: 1489.963 km
LOAD: 240 vol.
- Mainz Hbf | 80 vol.
- Saarbrücken Hbf | 70 vol.
- Würzburg Hbf | 90 vol.
LOAD: 280 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Leipzig Hbf | 20 vol.
- Dresden Hbf | 75 vol.
LOAD: 280 vol.
- München Hbf | 60 vol.
- Stuttgart Hbf | 80 vol.
- Karlsruhe Hbf | 80 vol.
- Mannheim Hbf | 60 vol.
LOAD: 235 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 40 vol.
LOAD: 240 vol.
- Mainz Hbf | 80 vol.
- Saarbrücken Hbf | 70 vol.
- Würzburg 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: 1035 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 45, 0, 0, 0, 80, 75, 35, 60, 75, 20, 70, 0, 80, 0, 0, 60, 40, 80, 90, 70, 85, 0] ITERATION Generation: #1 Best cost: 6450.779 | Path: [1, 0, 22, 10, 8, 11, 1, 7, 20, 19, 2, 1, 18, 12, 21, 17, 9, 1, 6, 14, 1] Best cost: 6239.969 | Path: [1, 6, 14, 17, 19, 1, 7, 11, 0, 12, 2, 1, 8, 18, 10, 22, 9, 1, 20, 21, 1] Best cost: 6215.995 | Path: [1, 8, 18, 10, 22, 2, 11, 1, 7, 20, 6, 1, 17, 14, 21, 19, 1, 0, 12, 9, 1] Best cost: 6168.831 | Path: [1, 9, 6, 14, 17, 11, 1, 7, 12, 2, 22, 1, 8, 18, 10, 0, 19, 1, 20, 21, 1] Best cost: 6146.894 | Path: [1, 21, 17, 14, 6, 1, 7, 11, 0, 12, 2, 1, 8, 18, 10, 22, 9, 1, 20, 19, 1] Best cost: 6145.380 | Path: [1, 19, 17, 14, 6, 1, 7, 11, 0, 22, 2, 1, 18, 8, 10, 12, 21, 1, 20, 9, 1] Best cost: 6123.515 | Path: [1, 8, 18, 10, 22, 2, 11, 1, 7, 0, 12, 19, 1, 20, 17, 14, 21, 1, 9, 6, 1] Best cost: 5841.434 | Path: [1, 9, 6, 14, 17, 11, 1, 7, 20, 19, 2, 1, 8, 18, 10, 22, 1, 0, 12, 21, 1] Best cost: 5768.359 | Path: [1, 9, 6, 14, 17, 11, 1, 7, 19, 21, 2, 1, 8, 18, 10, 22, 1, 0, 12, 20, 1] Generation: #6 Best cost: 5668.285 | Path: [1, 11, 7, 0, 12, 2, 1, 9, 6, 14, 17, 1, 8, 18, 10, 22, 1, 20, 19, 21, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 0, 12, 2, 1], [1, 9, 6, 14, 17, 1], [1, 8, 18, 10, 22, 1], [1, 20, 19, 21, 1]] [1] Cost: 1462.324 to 1367.158 | Optimized: [1, 12, 2, 0, 11, 7, 1] [3] Cost: 1132.488 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] [4] Cost: 1500.689 to 1489.963 | Optimized: [1, 19, 21, 20, 1] ACO RESULTS [1/280 vol./1367.158 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Kassel-Wilhelmshöhe -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [2/280 vol./1572.784 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Berlin Hbf [3/235 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/240 vol./1489.963 km] Berlin Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Würzburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5537.738 km.