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 (25 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (35 vol.)
- Dresden Hbf (60 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (90 vol.)
- Dortmund Hbf (65 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (30 vol.)
- Kiel Hbf (70 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (35 vol.)
- Osnabrück Hbf (60 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1366.798 km
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 25 vol.
- Dortmund Hbf | 65 vol.
- Osnabrück Hbf | 60 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 70 vol.
Tour 2
COST: 1306.217 km
LOAD: 280 vol.
- Dresden Hbf | 60 vol.
- Leipzig Hbf | 90 vol.
- Frankfurt Hbf | 90 vol.
- Würzburg Hbf | 40 vol.
Tour 3
COST: 2048.828 km
LOAD: 255 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 40 vol.
- Freiburg Hbf | 90 vol.
- Saarbrücken Hbf | 35 vol.
- Köln Hbf | 30 vol.
- Hannover Hbf | 35 vol.
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 25 vol.
- Dortmund Hbf | 65 vol.
- Osnabrück Hbf | 60 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 70 vol.
LOAD: 280 vol.
- Dresden Hbf | 60 vol.
- Leipzig Hbf | 90 vol.
- Frankfurt Hbf | 90 vol.
- Würzburg Hbf | 40 vol.
LOAD: 255 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 40 vol.
- Freiburg Hbf | 90 vol.
- Saarbrücken Hbf | 35 vol.
- Köln Hbf | 30 vol.
- Hannover Hbf | 35 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: 825 vol. | Vehicle capacity: 300 vol. Loads: [25, 0, 0, 90, 35, 0, 0, 60, 35, 25, 35, 90, 65, 0, 0, 40, 30, 0, 70, 0, 40, 35, 60, 90] ITERATION Generation: #1 Best cost: 5284.193 | Path: [1, 0, 12, 16, 22, 10, 8, 4, 1, 7, 11, 20, 3, 1, 18, 23, 21, 15, 9, 1] Best cost: 5278.178 | Path: [1, 7, 11, 4, 10, 22, 1, 8, 18, 12, 16, 3, 1, 0, 20, 15, 9, 21, 23, 1] Best cost: 5135.198 | Path: [1, 18, 8, 10, 4, 22, 12, 1, 11, 7, 9, 15, 20, 0, 1, 16, 3, 21, 23, 1] Best cost: 5029.388 | Path: [1, 4, 10, 8, 18, 22, 12, 1, 11, 7, 20, 3, 1, 0, 16, 21, 23, 15, 9, 1] Best cost: 4942.745 | Path: [1, 18, 8, 10, 22, 0, 12, 1, 11, 7, 20, 3, 1, 4, 16, 21, 23, 15, 9, 1] Best cost: 4901.417 | Path: [1, 8, 18, 10, 4, 22, 12, 1, 7, 11, 20, 3, 1, 0, 16, 21, 23, 15, 9, 1] Best cost: 4898.705 | Path: [1, 7, 11, 3, 20, 1, 8, 18, 10, 4, 22, 12, 1, 0, 16, 21, 23, 15, 9, 1] Best cost: 4778.851 | Path: [1, 0, 12, 22, 10, 8, 18, 1, 11, 7, 20, 3, 1, 4, 16, 21, 23, 15, 9, 1] OPTIMIZING each tour... Current: [[1, 0, 12, 22, 10, 8, 18, 1], [1, 11, 7, 20, 3, 1], [1, 4, 16, 21, 23, 15, 9, 1]] [2] Cost: 1344.791 to 1306.217 | Optimized: [1, 7, 11, 3, 20, 1] [3] Cost: 2067.262 to 2048.828 | Optimized: [1, 9, 15, 23, 21, 16, 4, 1] ACO RESULTS [1/290 vol./1366.798 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [2/280 vol./1306.217 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Frankfurt Hbf -> Würzburg Hbf --> Berlin Hbf [3/255 vol./2048.828 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Köln Hbf -> Hannover Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4721.843 km.