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
- Düsseldorf Hbf (45 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (70 vol.)
- Stuttgart Hbf (85 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (75 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (20 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (100 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (95 vol.)
- Kiel Hbf (30 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (70 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (100 vol.)
- Freiburg Hbf (100 vol.)
Tour 1
COST: 1164.369 km
LOAD: 385 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 100 vol.
- Stuttgart Hbf | 85 vol.
- Ulm Hbf | 100 vol.
Tour 2
COST: 1753.776 km
LOAD: 390 vol.
- Osnabrück Hbf | 100 vol.
- Hannover Hbf | 70 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 30 vol.
- Dresden Hbf | 25 vol.
- Nürnberg Hbf | 20 vol.
- Würzburg Hbf | 70 vol.
Tour 3
COST: 977.262 km
LOAD: 365 vol.
- Frankfurt Hbf | 90 vol.
- Mainz Hbf | 25 vol.
- Mannheim Hbf | 95 vol.
- Saarbrücken Hbf | 50 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 45 vol.
Tour 4
COST: 323.232 km
LOAD: 90 vol.
- Dortmund Hbf | 90 vol.
LOAD: 385 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 100 vol.
- Stuttgart Hbf | 85 vol.
- Ulm Hbf | 100 vol.
LOAD: 390 vol.
- Osnabrück Hbf | 100 vol.
- Hannover Hbf | 70 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 30 vol.
- Dresden Hbf | 25 vol.
- Nürnberg Hbf | 20 vol.
- Würzburg Hbf | 70 vol.
LOAD: 365 vol.
- Frankfurt Hbf | 90 vol.
- Mainz Hbf | 25 vol.
- Mannheim Hbf | 95 vol.
- Saarbrücken Hbf | 50 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 45 vol.
LOAD: 90 vol.
- Dortmund Hbf | 90 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: 1230 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 45, 90, 70, 0, 85, 25, 75, 0, 0, 0, 90, 20, 100, 100, 60, 95, 30, 25, 70, 50, 100, 100] ITERATION Generation: #1 Best cost: 4865.838 | Path: [0, 2, 16, 12, 22, 4, 18, 0, 3, 19, 17, 14, 6, 0, 20, 13, 15, 21, 23, 7, 0, 8, 0] Best cost: 4794.290 | Path: [0, 3, 19, 17, 14, 6, 0, 12, 2, 16, 22, 4, 18, 0, 20, 13, 15, 23, 21, 7, 0, 8, 0] Best cost: 4750.553 | Path: [0, 7, 13, 20, 3, 19, 17, 21, 0, 12, 2, 16, 22, 4, 18, 0, 6, 14, 23, 15, 0, 8, 0] Best cost: 4435.253 | Path: [0, 19, 3, 17, 14, 6, 0, 20, 13, 15, 23, 21, 2, 0, 12, 22, 4, 8, 18, 7, 0, 16, 0] Best cost: 4344.839 | Path: [0, 17, 14, 6, 15, 13, 0, 22, 4, 8, 18, 2, 16, 0, 3, 19, 21, 23, 20, 7, 0, 12, 0] Best cost: 4223.529 | Path: [0, 23, 14, 6, 15, 0, 22, 4, 8, 18, 7, 13, 20, 0, 3, 19, 17, 21, 16, 2, 0, 12, 0] OPTIMIZING each tour... Current: [[0, 23, 14, 6, 15, 0], [0, 22, 4, 8, 18, 7, 13, 20, 0], [0, 3, 19, 17, 21, 16, 2, 0], [0, 12, 0]] [1] Cost: 1169.259 to 1164.369 | Optimized: [0, 14, 23, 6, 15, 0] ACO RESULTS [1/385 vol./1164.369 km] Kassel-Wilhelmshöhe -> Karlsruhe Hbf -> Freiburg Hbf -> Stuttgart Hbf -> Ulm Hbf --> Kassel-Wilhelmshöhe [2/390 vol./1753.776 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf -> Dresden Hbf -> Nürnberg Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [3/365 vol./ 977.262 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Köln Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe [4/ 90 vol./ 323.232 km] Kassel-Wilhelmshöhe -> Dortmund Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4218.639 km.