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: 18 customers
- Berlin Hbf (65 vol.)
- Frankfurt Hbf (65 vol.)
- Aachen Hbf (95 vol.)
- Dresden Hbf (100 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (80 vol.)
- Leipzig Hbf (60 vol.)
- Dortmund Hbf (95 vol.)
- Nürnberg Hbf (90 vol.)
- Ulm Hbf (65 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (30 vol.)
- Kiel Hbf (85 vol.)
- Mainz Hbf (65 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (90 vol.)
- Osnabrück Hbf (80 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1035.387 km
LOAD: 380 vol.
- Frankfurt Hbf | 65 vol.
- Mainz Hbf | 65 vol.
- Mannheim Hbf | 30 vol.
- Saarbrücken Hbf | 90 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 35 vol.
Tour 2
COST: 1355.327 km
LOAD: 365 vol.
- Dortmund Hbf | 95 vol.
- Osnabrück Hbf | 80 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 85 vol.
- Berlin Hbf | 65 vol.
Tour 3
COST: 1377.149 km
LOAD: 395 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 65 vol.
- Freiburg Hbf | 80 vol.
Tour 4
COST: 758.587 km
LOAD: 160 vol.
- Dresden Hbf | 100 vol.
- Leipzig Hbf | 60 vol.
LOAD: 380 vol.
- Frankfurt Hbf | 65 vol.
- Mainz Hbf | 65 vol.
- Mannheim Hbf | 30 vol.
- Saarbrücken Hbf | 90 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 35 vol.
LOAD: 365 vol.
- Dortmund Hbf | 95 vol.
- Osnabrück Hbf | 80 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 85 vol.
- Berlin Hbf | 65 vol.
LOAD: 395 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 65 vol.
- Freiburg Hbf | 80 vol.
LOAD: 160 vol.
- Dresden Hbf | 100 vol.
- Leipzig Hbf | 60 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: 1300 vol. | Vehicle capacity: 400 vol. Loads: [0, 65, 0, 65, 0, 95, 0, 100, 40, 80, 0, 60, 95, 90, 0, 65, 35, 30, 85, 65, 80, 90, 80, 80] ITERATION Generation: #1 Best cost: 5291.543 | Path: [0, 1, 11, 7, 13, 20, 0, 12, 16, 5, 19, 3, 17, 0, 22, 8, 18, 21, 23, 0, 15, 9, 0] Best cost: 4917.597 | Path: [0, 7, 11, 1, 8, 18, 16, 0, 22, 12, 5, 19, 3, 0, 20, 13, 9, 15, 17, 0, 21, 23, 0] Best cost: 4801.830 | Path: [0, 16, 12, 22, 8, 18, 1, 0, 20, 13, 9, 15, 17, 0, 3, 19, 21, 23, 5, 0, 11, 7, 0] Best cost: 4749.781 | Path: [0, 22, 12, 16, 5, 3, 17, 0, 19, 21, 23, 15, 9, 0, 20, 13, 11, 7, 1, 0, 8, 18, 0] Best cost: 4747.944 | Path: [0, 1, 7, 11, 13, 20, 0, 22, 12, 16, 5, 19, 17, 0, 3, 21, 23, 15, 9, 0, 8, 18, 0] Best cost: 4670.045 | Path: [0, 3, 19, 17, 21, 5, 16, 0, 22, 12, 8, 18, 1, 0, 20, 13, 9, 15, 23, 0, 11, 7, 0] Best cost: 4650.586 | Path: [0, 22, 12, 16, 5, 19, 17, 0, 3, 20, 13, 9, 15, 0, 11, 7, 1, 8, 18, 0, 21, 23, 0] Best cost: 4607.407 | Path: [0, 22, 12, 16, 5, 3, 17, 0, 20, 13, 9, 15, 23, 0, 11, 7, 1, 8, 18, 0, 19, 21, 0] Best cost: 4589.170 | Path: [0, 3, 19, 17, 21, 16, 5, 0, 12, 22, 8, 18, 1, 0, 20, 13, 9, 15, 23, 0, 11, 7, 0] Best cost: 4529.506 | Path: [0, 3, 19, 17, 21, 5, 16, 0, 12, 22, 8, 18, 1, 0, 20, 13, 9, 15, 23, 0, 11, 7, 0] OPTIMIZING each tour... Current: [[0, 3, 19, 17, 21, 5, 16, 0], [0, 12, 22, 8, 18, 1, 0], [0, 20, 13, 9, 15, 23, 0], [0, 11, 7, 0]] [4] Cost: 761.643 to 758.587 | Optimized: [0, 7, 11, 0] ACO RESULTS [1/380 vol./1035.387 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe [2/365 vol./1355.327 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Osnabrück Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe [3/395 vol./1377.149 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [4/160 vol./ 758.587 km] Kassel-Wilhelmshöhe -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4526.450 km.