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: 22 customers
- Berlin Hbf (75 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (20 vol.)
- Stuttgart Hbf (25 vol.)
- Dresden Hbf (100 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (70 vol.)
- Dortmund Hbf (100 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (35 vol.)
- Ulm Hbf (85 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (95 vol.)
- Kiel Hbf (75 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (25 vol.)
- Osnabrück Hbf (75 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1446.488 km
LOAD: 395 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 75 vol.
- Berlin Hbf | 75 vol.
- Dresden Hbf | 100 vol.
- Leipzig Hbf | 70 vol.
Tour 2
COST: 931.715 km
LOAD: 395 vol.
- Aachen Hbf | 20 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 90 vol.
- Dortmund Hbf | 100 vol.
- Osnabrück Hbf | 75 vol.
- Hannover Hbf | 50 vol.
Tour 3
COST: 1329.178 km
LOAD: 400 vol.
- Würzburg Hbf | 50 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 85 vol.
- Stuttgart Hbf | 25 vol.
- Karlsruhe Hbf | 35 vol.
- Saarbrücken Hbf | 25 vol.
Tour 4
COST: 938.605 km
LOAD: 225 vol.
- Frankfurt Hbf | 60 vol.
- Mannheim Hbf | 95 vol.
- Freiburg Hbf | 70 vol.
LOAD: 395 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 75 vol.
- Berlin Hbf | 75 vol.
- Dresden Hbf | 100 vol.
- Leipzig Hbf | 70 vol.
LOAD: 395 vol.
- Aachen Hbf | 20 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 90 vol.
- Dortmund Hbf | 100 vol.
- Osnabrück Hbf | 75 vol.
- Hannover Hbf | 50 vol.
LOAD: 400 vol.
- Würzburg Hbf | 50 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 85 vol.
- Stuttgart Hbf | 25 vol.
- Karlsruhe Hbf | 35 vol.
- Saarbrücken Hbf | 25 vol.
LOAD: 225 vol.
- Frankfurt Hbf | 60 vol.
- Mannheim Hbf | 95 vol.
- Freiburg Hbf | 70 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: 1415 vol. | Vehicle capacity: 400 vol. Loads: [0, 75, 90, 60, 50, 20, 25, 100, 40, 100, 35, 70, 100, 80, 35, 85, 60, 95, 75, 0, 50, 25, 75, 70] ITERATION Generation: #1 Best cost: 6498.522 | Path: [0, 1, 11, 7, 4, 10, 8, 5, 0, 12, 2, 16, 17, 14, 0, 22, 18, 3, 20, 13, 6, 21, 0, 9, 15, 23, 0] Best cost: 5536.113 | Path: [0, 2, 16, 5, 12, 22, 10, 0, 4, 8, 18, 1, 11, 20, 14, 0, 3, 17, 21, 23, 15, 6, 0, 13, 9, 7, 0] Best cost: 5270.205 | Path: [0, 7, 11, 1, 10, 8, 18, 0, 3, 17, 14, 6, 15, 9, 0, 12, 2, 16, 5, 21, 23, 0, 4, 22, 20, 13, 0] Best cost: 5264.059 | Path: [0, 9, 13, 20, 3, 17, 0, 4, 10, 8, 18, 22, 12, 5, 0, 16, 2, 21, 14, 6, 15, 23, 0, 11, 7, 1, 0] Best cost: 5152.873 | Path: [0, 21, 14, 6, 15, 9, 13, 20, 0, 3, 17, 23, 16, 2, 5, 0, 4, 22, 10, 8, 18, 1, 0, 12, 11, 7, 0] Best cost: 5068.163 | Path: [0, 22, 10, 8, 18, 4, 12, 5, 0, 2, 16, 3, 17, 14, 6, 21, 0, 20, 13, 9, 15, 23, 0, 11, 7, 1, 0] Best cost: 4956.253 | Path: [0, 8, 18, 10, 4, 22, 12, 5, 0, 20, 13, 9, 15, 6, 14, 21, 0, 3, 17, 23, 16, 2, 0, 11, 7, 1, 0] Best cost: 4832.678 | Path: [0, 11, 7, 1, 18, 8, 10, 0, 12, 2, 16, 5, 22, 4, 0, 3, 17, 14, 6, 15, 9, 0, 20, 13, 23, 21, 0] Best cost: 4765.942 | Path: [0, 7, 11, 1, 8, 18, 10, 0, 4, 22, 12, 2, 16, 5, 0, 20, 13, 9, 15, 6, 14, 21, 0, 3, 17, 23, 0] Generation: #2 Best cost: 4675.315 | Path: [0, 11, 7, 1, 8, 18, 10, 0, 4, 22, 12, 2, 16, 5, 0, 20, 13, 9, 15, 6, 14, 21, 0, 3, 17, 23, 0] Best cost: 4667.691 | Path: [0, 11, 7, 1, 8, 18, 10, 0, 12, 2, 16, 5, 22, 4, 0, 20, 13, 9, 15, 6, 14, 21, 0, 3, 17, 23, 0] OPTIMIZING each tour... Current: [[0, 11, 7, 1, 8, 18, 10, 0], [0, 12, 2, 16, 5, 22, 4, 0], [0, 20, 13, 9, 15, 6, 14, 21, 0], [0, 3, 17, 23, 0]] [1] Cost: 1467.917 to 1446.488 | Optimized: [0, 10, 8, 18, 1, 7, 11, 0] [2] Cost: 931.991 to 931.715 | Optimized: [0, 5, 16, 2, 12, 22, 4, 0] ACO RESULTS [1/395 vol./1446.488 km] Kassel-Wilhelmshöhe -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/395 vol./ 931.715 km] Kassel-Wilhelmshöhe -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe [3/400 vol./1329.178 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf --> Kassel-Wilhelmshöhe [4/225 vol./ 938.605 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mannheim Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4645.986 km.