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: 15 customers
- Berlin Hbf (20 vol.)
- Aachen Hbf (85 vol.)
- Stuttgart Hbf (55 vol.)
- Hamburg Hbf (75 vol.)
- München Hbf (75 vol.)
- Bremen Hbf (85 vol.)
- Leipzig Hbf (45 vol.)
- Dortmund Hbf (60 vol.)
- Karlsruhe Hbf (100 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (100 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (100 vol.)
Tour 1
COST: 1097.439 km
LOAD: 400 vol.
- Dortmund Hbf | 60 vol.
- Aachen Hbf | 85 vol.
- Saarbrücken Hbf | 30 vol.
- Karlsruhe Hbf | 100 vol.
- Mannheim Hbf | 25 vol.
- Mainz Hbf | 100 vol.
Tour 2
COST: 1256.055 km
LOAD: 370 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 90 vol.
- Berlin Hbf | 20 vol.
Tour 3
COST: 1282.384 km
LOAD: 275 vol.
- Leipzig Hbf | 45 vol.
- München Hbf | 75 vol.
- Stuttgart Hbf | 55 vol.
- Würzburg Hbf | 100 vol.
LOAD: 400 vol.
- Dortmund Hbf | 60 vol.
- Aachen Hbf | 85 vol.
- Saarbrücken Hbf | 30 vol.
- Karlsruhe Hbf | 100 vol.
- Mannheim Hbf | 25 vol.
- Mainz Hbf | 100 vol.
LOAD: 370 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 90 vol.
- Berlin Hbf | 20 vol.
LOAD: 275 vol.
- Leipzig Hbf | 45 vol.
- München Hbf | 75 vol.
- Stuttgart Hbf | 55 vol.
- Würzburg 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1045 vol. | Vehicle capacity: 400 vol. Loads: [0, 20, 0, 0, 0, 85, 55, 0, 75, 75, 85, 45, 60, 0, 100, 0, 0, 25, 90, 100, 100, 30, 100, 0] ITERATION Generation: #1 Best cost: 4649.047 | Path: [0, 1, 11, 20, 19, 17, 14, 0, 22, 10, 8, 18, 21, 0, 12, 5, 6, 9, 0] Best cost: 4472.851 | Path: [0, 5, 12, 22, 10, 1, 11, 0, 19, 17, 14, 6, 20, 0, 8, 18, 21, 9, 0] Best cost: 4406.456 | Path: [0, 6, 14, 17, 19, 20, 1, 0, 22, 12, 5, 21, 9, 11, 0, 10, 8, 18, 0] Best cost: 4217.183 | Path: [0, 8, 18, 10, 22, 11, 0, 12, 5, 19, 17, 14, 21, 0, 20, 6, 9, 1, 0] Best cost: 4098.708 | Path: [0, 14, 17, 19, 21, 6, 9, 0, 22, 10, 8, 18, 1, 0, 12, 5, 20, 11, 0] Best cost: 3974.030 | Path: [0, 22, 12, 5, 19, 17, 21, 0, 20, 6, 14, 9, 11, 1, 0, 10, 8, 18, 0] Best cost: 3920.133 | Path: [0, 14, 17, 19, 21, 5, 12, 0, 22, 10, 8, 18, 1, 0, 11, 20, 6, 9, 0] Best cost: 3777.498 | Path: [0, 12, 5, 19, 17, 14, 21, 0, 22, 10, 8, 18, 1, 0, 20, 6, 9, 11, 0] Best cost: 3754.576 | Path: [0, 14, 17, 19, 21, 5, 12, 0, 22, 10, 8, 18, 1, 0, 20, 6, 9, 11, 0] Best cost: 3746.086 | Path: [0, 1, 11, 9, 6, 14, 17, 21, 0, 22, 10, 8, 18, 0, 12, 5, 19, 20, 0] Generation: #3 Best cost: 3738.535 | Path: [0, 1, 11, 9, 6, 14, 17, 21, 0, 8, 18, 10, 22, 0, 12, 5, 19, 20, 0] Generation: #6 Best cost: 3647.434 | Path: [0, 12, 5, 21, 14, 17, 19, 0, 22, 10, 8, 18, 1, 0, 20, 6, 9, 11, 0] OPTIMIZING each tour... Current: [[0, 12, 5, 21, 14, 17, 19, 0], [0, 22, 10, 8, 18, 1, 0], [0, 20, 6, 9, 11, 0]] [3] Cost: 1293.940 to 1282.384 | Optimized: [0, 11, 9, 6, 20, 0] ACO RESULTS [1/400 vol./1097.439 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe [2/370 vol./1256.055 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe [3/275 vol./1282.384 km] Kassel-Wilhelmshöhe -> Leipzig Hbf -> München Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3635.878 km.