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: 15 customers
- Kassel-Wilhelmshöhe (50 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (80 vol.)
- Dresden Hbf (20 vol.)
- Leipzig Hbf (70 vol.)
- Dortmund Hbf (80 vol.)
- Nürnberg Hbf (45 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (20 vol.)
- Mannheim Hbf (35 vol.)
- Würzburg Hbf (45 vol.)
- Saarbrücken Hbf (95 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1954.096 km
LOAD: 295 vol.
- Dresden Hbf | 20 vol.
- Ulm Hbf | 20 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 60 vol.
- Saarbrücken Hbf | 95 vol.
- Mannheim Hbf | 35 vol.
Tour 2
COST: 1290.188 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Frankfurt Hbf | 90 vol.
- Würzburg Hbf | 45 vol.
- Nürnberg Hbf | 45 vol.
- Leipzig Hbf | 70 vol.
Tour 3
COST: 1331.929 km
LOAD: 290 vol.
- Dortmund Hbf | 80 vol.
- Aachen Hbf | 80 vol.
- Osnabrück Hbf | 85 vol.
- Hannover Hbf | 45 vol.
LOAD: 295 vol.
- Dresden Hbf | 20 vol.
- Ulm Hbf | 20 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 60 vol.
- Saarbrücken Hbf | 95 vol.
- Mannheim Hbf | 35 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Frankfurt Hbf | 90 vol.
- Würzburg Hbf | 45 vol.
- Nürnberg Hbf | 45 vol.
- Leipzig Hbf | 70 vol.
LOAD: 290 vol.
- Dortmund Hbf | 80 vol.
- Aachen Hbf | 80 vol.
- Osnabrück Hbf | 85 vol.
- Hannover Hbf | 45 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: 885 vol. | Vehicle capacity: 300 vol. Loads: [50, 0, 0, 90, 45, 80, 0, 20, 0, 0, 0, 70, 80, 45, 65, 20, 0, 35, 0, 0, 45, 95, 85, 60] ITERATION Generation: #1 Best cost: 5690.581 | Path: [1, 0, 12, 22, 4, 7, 15, 1, 11, 13, 20, 3, 17, 1, 5, 21, 14, 23, 1] Best cost: 5379.133 | Path: [1, 3, 20, 17, 14, 23, 1, 11, 7, 4, 22, 12, 1, 0, 13, 15, 21, 5, 1] Best cost: 5070.347 | Path: [1, 4, 22, 12, 5, 1, 11, 7, 20, 13, 14, 17, 15, 1, 0, 3, 21, 23, 1] Best cost: 4950.561 | Path: [1, 7, 11, 4, 22, 12, 1, 0, 3, 17, 14, 23, 1, 13, 20, 15, 21, 5, 1] Best cost: 4897.263 | Path: [1, 7, 11, 4, 22, 12, 1, 13, 20, 3, 17, 14, 15, 1, 0, 5, 21, 23, 1] Best cost: 4838.074 | Path: [1, 21, 23, 14, 17, 20, 1, 11, 7, 13, 15, 3, 0, 1, 4, 22, 12, 5, 1] Best cost: 4663.918 | Path: [1, 17, 14, 23, 21, 15, 7, 1, 11, 13, 20, 3, 0, 1, 4, 22, 12, 5, 1] OPTIMIZING each tour... Current: [[1, 17, 14, 23, 21, 15, 7, 1], [1, 11, 13, 20, 3, 0, 1], [1, 4, 22, 12, 5, 1]] [1] Cost: 2026.575 to 1954.096 | Optimized: [1, 7, 15, 14, 23, 21, 17, 1] [2] Cost: 1297.040 to 1290.188 | Optimized: [1, 0, 3, 20, 13, 11, 1] [3] Cost: 1340.303 to 1331.929 | Optimized: [1, 12, 5, 22, 4, 1] ACO RESULTS [1/295 vol./1954.096 km] Berlin Hbf -> Dresden Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mannheim Hbf --> Berlin Hbf [2/300 vol./1290.188 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [3/290 vol./1331.929 km] Berlin Hbf -> Dortmund Hbf -> Aachen Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4576.213 km.