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: 20 customers
- Berlin Hbf (70 vol.)
- Düsseldorf Hbf (70 vol.)
- Frankfurt Hbf (100 vol.)
- Hannover Hbf (70 vol.)
- Aachen Hbf (25 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (95 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (55 vol.)
- Karlsruhe Hbf (60 vol.)
- Ulm Hbf (55 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (35 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (90 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 876.38 km
LOAD: 385 vol.
- Mannheim Hbf | 35 vol.
- Karlsruhe Hbf | 60 vol.
- Saarbrücken Hbf | 90 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 100 vol.
Tour 2
COST: 1000.319 km
LOAD: 350 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 25 vol.
- Düsseldorf Hbf | 70 vol.
- Dortmund Hbf | 85 vol.
- Bremen Hbf | 100 vol.
Tour 3
COST: 1377.149 km
LOAD: 375 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 55 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 55 vol.
- Freiburg Hbf | 85 vol.
Tour 4
COST: 1197.302 km
LOAD: 400 vol.
- Hannover Hbf | 70 vol.
- Hamburg Hbf | 90 vol.
- Berlin Hbf | 70 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 95 vol.
LOAD: 385 vol.
- Mannheim Hbf | 35 vol.
- Karlsruhe Hbf | 60 vol.
- Saarbrücken Hbf | 90 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 100 vol.
LOAD: 350 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 25 vol.
- Düsseldorf Hbf | 70 vol.
- Dortmund Hbf | 85 vol.
- Bremen Hbf | 100 vol.
LOAD: 375 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 55 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 55 vol.
- Freiburg Hbf | 85 vol.
LOAD: 400 vol.
- Hannover Hbf | 70 vol.
- Hamburg Hbf | 90 vol.
- Berlin Hbf | 70 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 95 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: 1510 vol. | Vehicle capacity: 400 vol. Loads: [0, 70, 70, 100, 70, 25, 0, 75, 90, 95, 100, 95, 85, 55, 60, 55, 70, 35, 0, 100, 85, 90, 0, 85] ITERATION Generation: #1 Best cost: 5352.531 | Path: [0, 1, 11, 7, 13, 20, 0, 12, 2, 16, 5, 21, 14, 0, 19, 3, 17, 23, 15, 0, 4, 10, 8, 9, 0] Best cost: 4988.169 | Path: [0, 3, 19, 17, 14, 23, 0, 20, 13, 9, 15, 21, 0, 12, 2, 16, 5, 4, 1, 0, 11, 7, 10, 8, 0] Best cost: 4530.964 | Path: [0, 19, 3, 17, 14, 21, 0, 12, 2, 16, 5, 10, 0, 4, 8, 1, 7, 11, 0, 20, 13, 9, 15, 23, 0] Best cost: 4508.537 | Path: [0, 3, 19, 17, 14, 21, 0, 12, 2, 16, 5, 10, 0, 20, 13, 9, 15, 23, 0, 4, 8, 1, 7, 11, 0] OPTIMIZING each tour... Current: [[0, 3, 19, 17, 14, 21, 0], [0, 12, 2, 16, 5, 10, 0], [0, 20, 13, 9, 15, 23, 0], [0, 4, 8, 1, 7, 11, 0]] [1] Cost: 914.236 to 876.380 | Optimized: [0, 17, 14, 21, 19, 3, 0] [2] Cost: 1019.850 to 1000.319 | Optimized: [0, 16, 5, 2, 12, 10, 0] ACO RESULTS [1/385 vol./ 876.380 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [2/350 vol./1000.319 km] Kassel-Wilhelmshöhe -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Bremen Hbf --> Kassel-Wilhelmshöhe [3/375 vol./1377.149 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [4/400 vol./1197.302 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4451.150 km.