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 (25 vol.)
- Frankfurt Hbf (30 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (55 vol.)
- Dresden Hbf (65 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (65 vol.)
- Dortmund Hbf (80 vol.)
- Nürnberg Hbf (85 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (65 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (30 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (30 vol.)
Tour 1
COST: 1054.241 km
LOAD: 390 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 30 vol.
- Mannheim Hbf | 65 vol.
- Saarbrücken Hbf | 70 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 65 vol.
- Dortmund Hbf | 80 vol.
Tour 2
COST: 1421.064 km
LOAD: 375 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 100 vol.
- Kiel Hbf | 95 vol.
- Berlin Hbf | 25 vol.
- Dresden Hbf | 65 vol.
Tour 3
COST: 1623.963 km
LOAD: 395 vol.
- Leipzig Hbf | 65 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 55 vol.
- Freiburg Hbf | 30 vol.
LOAD: 390 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 30 vol.
- Mannheim Hbf | 65 vol.
- Saarbrücken Hbf | 70 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 65 vol.
- Dortmund Hbf | 80 vol.
LOAD: 375 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 100 vol.
- Kiel Hbf | 95 vol.
- Berlin Hbf | 25 vol.
- Dresden Hbf | 65 vol.
LOAD: 395 vol.
- Leipzig Hbf | 65 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 55 vol.
- Freiburg Hbf | 30 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: 1160 vol. | Vehicle capacity: 400 vol. Loads: [0, 25, 0, 30, 0, 50, 55, 65, 0, 80, 100, 65, 80, 85, 0, 80, 65, 65, 95, 30, 0, 70, 90, 30] ITERATION Generation: #1 Best cost: 4837.412 | Path: [0, 1, 7, 11, 13, 9, 15, 0, 12, 16, 5, 19, 3, 17, 6, 0, 22, 10, 18, 21, 23, 0] Best cost: 4832.019 | Path: [0, 11, 7, 1, 18, 10, 5, 0, 22, 12, 16, 3, 19, 17, 23, 0, 13, 15, 6, 9, 21, 0] Best cost: 4483.981 | Path: [0, 13, 9, 15, 6, 17, 19, 0, 12, 16, 5, 3, 21, 23, 11, 0, 22, 10, 18, 1, 7, 0] Best cost: 4405.360 | Path: [0, 12, 16, 5, 19, 3, 17, 21, 0, 22, 10, 18, 1, 7, 0, 11, 13, 9, 6, 15, 23, 0] Best cost: 4331.321 | Path: [0, 22, 10, 18, 1, 7, 0, 19, 3, 17, 21, 16, 5, 12, 0, 11, 13, 9, 6, 15, 23, 0] Best cost: 4274.026 | Path: [0, 12, 16, 5, 3, 19, 17, 21, 0, 22, 10, 18, 1, 7, 0, 11, 13, 9, 15, 6, 23, 0] Best cost: 4263.765 | Path: [0, 21, 17, 19, 3, 16, 5, 12, 0, 22, 10, 18, 1, 7, 0, 11, 13, 9, 15, 6, 23, 0] Best cost: 4099.839 | Path: [0, 12, 16, 5, 21, 17, 19, 3, 0, 22, 10, 18, 1, 7, 0, 11, 13, 9, 15, 6, 23, 0] Generation: #3 Best cost: 4099.268 | Path: [0, 3, 19, 17, 21, 5, 16, 12, 0, 22, 10, 18, 1, 7, 0, 11, 13, 9, 15, 6, 23, 0] OPTIMIZING each tour... Current: [[0, 3, 19, 17, 21, 5, 16, 12, 0], [0, 22, 10, 18, 1, 7, 0], [0, 11, 13, 9, 15, 6, 23, 0]] No changes made. ACO RESULTS [1/390 vol./1054.241 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [2/375 vol./1421.064 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf --> Kassel-Wilhelmshöhe [3/395 vol./1623.963 km] Kassel-Wilhelmshöhe -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4099.268 km.