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: 21 customers
- Berlin Hbf (25 vol.)
- Düsseldorf Hbf (30 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (70 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (35 vol.)
- München Hbf (70 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (65 vol.)
- Dortmund Hbf (45 vol.)
- Nürnberg Hbf (60 vol.)
- Ulm Hbf (30 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (35 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (45 vol.)
- Würzburg Hbf (20 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (45 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1292.339 km
LOAD: 395 vol.
- Würzburg Hbf | 20 vol.
- Frankfurt Hbf | 40 vol.
- Mannheim Hbf | 35 vol.
- Saarbrücken Hbf | 80 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 30 vol.
- Dortmund Hbf | 45 vol.
- Osnabrück Hbf | 45 vol.
Tour 2
COST: 1441.48 km
LOAD: 375 vol.
- Hannover Hbf | 70 vol.
- Bremen Hbf | 90 vol.
- Kiel Hbf | 90 vol.
- Berlin Hbf | 25 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 65 vol.
Tour 3
COST: 1421.487 km
LOAD: 350 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 70 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 60 vol.
- Freiburg Hbf | 85 vol.
- Mainz Hbf | 45 vol.
LOAD: 395 vol.
- Würzburg Hbf | 20 vol.
- Frankfurt Hbf | 40 vol.
- Mannheim Hbf | 35 vol.
- Saarbrücken Hbf | 80 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 30 vol.
- Dortmund Hbf | 45 vol.
- Osnabrück Hbf | 45 vol.
LOAD: 375 vol.
- Hannover Hbf | 70 vol.
- Bremen Hbf | 90 vol.
- Kiel Hbf | 90 vol.
- Berlin Hbf | 25 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 65 vol.
LOAD: 350 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 70 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 60 vol.
- Freiburg Hbf | 85 vol.
- Mainz 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1120 vol. | Vehicle capacity: 400 vol. Loads: [0, 25, 30, 40, 70, 40, 60, 35, 0, 70, 90, 65, 45, 60, 0, 30, 60, 35, 90, 45, 20, 80, 45, 85] ITERATION Generation: #1 Best cost: 5856.412 | Path: [0, 1, 11, 7, 4, 10, 22, 12, 20, 0, 2, 16, 5, 17, 19, 3, 6, 15, 13, 0, 18, 21, 23, 9, 0] Best cost: 5551.267 | Path: [0, 2, 16, 5, 12, 22, 10, 4, 20, 0, 3, 19, 17, 6, 15, 9, 13, 7, 1, 0, 11, 21, 23, 18, 0] Best cost: 4905.505 | Path: [0, 3, 19, 17, 6, 15, 9, 13, 20, 5, 0, 22, 4, 10, 18, 1, 11, 0, 12, 2, 16, 21, 23, 7, 0] Best cost: 4722.183 | Path: [0, 15, 6, 17, 19, 3, 20, 13, 9, 7, 0, 22, 12, 2, 16, 5, 21, 23, 0, 4, 10, 18, 1, 11, 0] Best cost: 4464.833 | Path: [0, 18, 10, 22, 12, 2, 16, 5, 0, 3, 19, 17, 21, 23, 6, 15, 20, 0, 4, 1, 7, 11, 13, 9, 0] Best cost: 4420.921 | Path: [0, 3, 19, 17, 21, 23, 6, 15, 20, 0, 12, 2, 16, 5, 22, 10, 4, 0, 13, 9, 11, 7, 1, 18, 0] Generation: #2 Best cost: 4299.445 | Path: [0, 22, 12, 2, 16, 5, 21, 17, 3, 20, 0, 4, 10, 18, 1, 7, 11, 0, 19, 13, 9, 15, 6, 23, 0] Generation: #5 Best cost: 4276.433 | Path: [0, 22, 12, 2, 16, 5, 21, 17, 3, 20, 0, 4, 10, 18, 1, 11, 7, 0, 19, 23, 6, 15, 9, 13, 0] OPTIMIZING each tour... Current: [[0, 22, 12, 2, 16, 5, 21, 17, 3, 20, 0], [0, 4, 10, 18, 1, 11, 7, 0], [0, 19, 23, 6, 15, 9, 13, 0]] [1] Cost: 1304.410 to 1292.339 | Optimized: [0, 20, 3, 17, 21, 5, 16, 2, 12, 22, 0] [2] Cost: 1536.492 to 1441.480 | Optimized: [0, 4, 10, 18, 1, 7, 11, 0] [3] Cost: 1435.531 to 1421.487 | Optimized: [0, 13, 9, 15, 6, 23, 19, 0] ACO RESULTS [1/395 vol./1292.339 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe [2/375 vol./1441.480 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/350 vol./1421.487 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4155.306 km.