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: 400 vol.
ACTIVE: 17 customers
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (65 vol.)
- Stuttgart Hbf (80 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (65 vol.)
- Leipzig Hbf (45 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (50 vol.)
- Ulm Hbf (65 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (35 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (45 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (70 vol.)
Tour 1
COST: 1049.193 km
LOAD: 380 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 35 vol.
- Saarbrücken Hbf | 80 vol.
- Aachen Hbf | 65 vol.
- Köln Hbf | 35 vol.
- Düsseldorf Hbf | 65 vol.
- Dortmund Hbf | 55 vol.
Tour 2
COST: 1362.212 km
LOAD: 400 vol.
- Leipzig Hbf | 45 vol.
- Nürnberg Hbf | 50 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 80 vol.
- Frankfurt Hbf | 60 vol.
Tour 3
COST: 1003.828 km
LOAD: 280 vol.
- Hannover Hbf | 95 vol.
- Bremen Hbf | 65 vol.
- Kiel Hbf | 50 vol.
- Osnabrück Hbf | 70 vol.
LOAD: 380 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 35 vol.
- Saarbrücken Hbf | 80 vol.
- Aachen Hbf | 65 vol.
- Köln Hbf | 35 vol.
- Düsseldorf Hbf | 65 vol.
- Dortmund Hbf | 55 vol.
LOAD: 400 vol.
- Leipzig Hbf | 45 vol.
- Nürnberg Hbf | 50 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 80 vol.
- Frankfurt Hbf | 60 vol.
LOAD: 280 vol.
- Hannover Hbf | 95 vol.
- Bremen Hbf | 65 vol.
- Kiel Hbf | 50 vol.
- Osnabrück 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1060 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 65, 60, 95, 65, 80, 0, 0, 100, 65, 45, 55, 50, 0, 65, 35, 35, 50, 45, 0, 80, 70, 0] ITERATION Generation: #1 Best cost: 4265.227 | Path: [0, 2, 16, 5, 12, 22, 4, 0, 19, 3, 17, 21, 6, 15, 0, 11, 13, 9, 10, 18, 0] Best cost: 4117.671 | Path: [0, 3, 19, 17, 6, 15, 9, 0, 22, 10, 4, 18, 2, 16, 0, 12, 5, 21, 13, 11, 0] Best cost: 4066.750 | Path: [0, 6, 15, 13, 9, 17, 19, 0, 12, 2, 16, 5, 21, 3, 0, 22, 10, 4, 11, 18, 0] Best cost: 3668.110 | Path: [0, 13, 9, 15, 6, 17, 3, 0, 12, 2, 16, 5, 21, 19, 11, 0, 22, 10, 4, 18, 0] Best cost: 3658.625 | Path: [0, 12, 2, 16, 5, 21, 19, 17, 0, 3, 6, 15, 9, 13, 11, 0, 4, 10, 22, 18, 0] Best cost: 3556.387 | Path: [0, 13, 9, 15, 6, 17, 19, 0, 12, 2, 16, 5, 21, 3, 0, 22, 4, 10, 18, 11, 0] Generation: #3 Best cost: 3515.429 | Path: [0, 12, 2, 16, 5, 21, 17, 19, 0, 3, 6, 15, 9, 13, 11, 0, 22, 10, 4, 18, 0] Generation: #6 Best cost: 3500.585 | Path: [0, 12, 2, 16, 5, 21, 17, 19, 0, 11, 13, 9, 15, 6, 3, 0, 22, 10, 4, 18, 0] OPTIMIZING each tour... Current: [[0, 12, 2, 16, 5, 21, 17, 19, 0], [0, 11, 13, 9, 15, 6, 3, 0], [0, 22, 10, 4, 18, 0]] [1] Cost: 1051.043 to 1049.193 | Optimized: [0, 19, 17, 21, 5, 16, 2, 12, 0] [3] Cost: 1087.330 to 1003.828 | Optimized: [0, 4, 10, 18, 22, 0] ACO RESULTS [1/380 vol./1049.193 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1362.212 km] Kassel-Wilhelmshöhe -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/280 vol./1003.828 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Kiel Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3415.233 km.