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: 19 customers
- Berlin Hbf (75 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (100 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (95 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (20 vol.)
- Dortmund Hbf (35 vol.)
- Nürnberg Hbf (85 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (20 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (85 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (25 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1213.375 km
LOAD: 395 vol.
- Köln Hbf | 20 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 85 vol.
- Hannover Hbf | 85 vol.
Tour 2
COST: 1078.186 km
LOAD: 380 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 100 vol.
- Würzburg Hbf | 95 vol.
Tour 3
COST: 1271.212 km
LOAD: 330 vol.
- Dortmund Hbf | 35 vol.
- Aachen Hbf | 45 vol.
- Saarbrücken Hbf | 25 vol.
- Freiburg Hbf | 35 vol.
- Mannheim Hbf | 100 vol.
- Frankfurt Hbf | 90 vol.
Tour 4
COST: 960.522 km
LOAD: 165 vol.
- Dresden Hbf | 90 vol.
- Berlin Hbf | 75 vol.
LOAD: 395 vol.
- Köln Hbf | 20 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 85 vol.
- Hannover Hbf | 85 vol.
LOAD: 380 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 100 vol.
- Würzburg Hbf | 95 vol.
LOAD: 330 vol.
- Dortmund Hbf | 35 vol.
- Aachen Hbf | 45 vol.
- Saarbrücken Hbf | 25 vol.
- Freiburg Hbf | 35 vol.
- Mannheim Hbf | 100 vol.
- Frankfurt Hbf | 90 vol.
LOAD: 165 vol.
- Dresden Hbf | 90 vol.
- Berlin Hbf | 75 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: 1270 vol. | Vehicle capacity: 400 vol. Loads: [0, 75, 0, 90, 85, 45, 100, 90, 95, 80, 20, 0, 35, 85, 0, 20, 20, 100, 85, 0, 95, 25, 90, 35] ITERATION Generation: #1 Best cost: 6109.964 | Path: [0, 1, 7, 4, 10, 22, 12, 0, 3, 17, 21, 16, 5, 6, 15, 0, 8, 18, 20, 13, 23, 0, 9, 0] Best cost: 5733.338 | Path: [0, 3, 17, 21, 23, 6, 15, 16, 0, 12, 22, 10, 4, 8, 1, 0, 20, 13, 9, 7, 5, 0, 18, 0] Best cost: 5140.491 | Path: [0, 4, 10, 22, 12, 16, 5, 17, 0, 20, 3, 21, 23, 15, 6, 0, 13, 9, 7, 1, 0, 8, 18, 0] Best cost: 4899.423 | Path: [0, 7, 1, 18, 8, 10, 12, 0, 4, 22, 16, 5, 3, 21, 23, 0, 20, 13, 9, 15, 6, 0, 17, 0] Best cost: 4877.460 | Path: [0, 23, 6, 15, 9, 13, 21, 16, 12, 0, 22, 10, 8, 18, 4, 0, 20, 3, 17, 5, 0, 1, 7, 0] Best cost: 4741.921 | Path: [0, 7, 1, 8, 18, 10, 12, 0, 4, 22, 16, 5, 21, 23, 3, 0, 20, 13, 9, 15, 6, 0, 17, 0] Generation: #2 Best cost: 4704.335 | Path: [0, 7, 1, 8, 18, 10, 12, 0, 4, 22, 16, 5, 21, 17, 23, 0, 20, 13, 9, 15, 6, 0, 3, 0] Generation: #3 Best cost: 4659.632 | Path: [0, 8, 18, 10, 4, 22, 16, 0, 20, 13, 9, 15, 6, 0, 12, 5, 21, 23, 17, 3, 0, 7, 1, 0] Generation: #7 Best cost: 4609.491 | Path: [0, 4, 10, 8, 18, 22, 16, 0, 20, 13, 9, 15, 6, 0, 12, 5, 21, 23, 17, 3, 0, 7, 1, 0] OPTIMIZING each tour... Current: [[0, 4, 10, 8, 18, 22, 16, 0], [0, 20, 13, 9, 15, 6, 0], [0, 12, 5, 21, 23, 17, 3, 0], [0, 7, 1, 0]] [1] Cost: 1292.430 to 1213.375 | Optimized: [0, 16, 22, 10, 8, 18, 4, 0] [2] Cost: 1085.327 to 1078.186 | Optimized: [0, 13, 9, 15, 6, 20, 0] ACO RESULTS [1/395 vol./1213.375 km] Kassel-Wilhelmshöhe -> Köln Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe [2/380 vol./1078.186 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [3/330 vol./1271.212 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Mannheim Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [4/165 vol./ 960.522 km] Kassel-Wilhelmshöhe -> Dresden Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4523.295 km.