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 (55 vol.)
- Düsseldorf Hbf (40 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (45 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (80 vol.)
- Leipzig Hbf (75 vol.)
- Dortmund Hbf (80 vol.)
- Nürnberg Hbf (70 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (70 vol.)
- Köln Hbf (40 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (30 vol.)
- Mainz Hbf (100 vol.)
- Saarbrücken Hbf (90 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1158.619 km
LOAD: 400 vol.
- Nürnberg Hbf | 70 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 70 vol.
- Karlsruhe Hbf | 45 vol.
- Mannheim Hbf | 90 vol.
- Mainz Hbf | 100 vol.
Tour 2
COST: 1273.969 km
LOAD: 375 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 90 vol.
- Aachen Hbf | 45 vol.
- Köln Hbf | 40 vol.
- Düsseldorf Hbf | 40 vol.
- Dortmund Hbf | 80 vol.
Tour 3
COST: 1446.488 km
LOAD: 390 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 30 vol.
- Berlin Hbf | 55 vol.
- Dresden Hbf | 70 vol.
- Leipzig Hbf | 75 vol.
Tour 4
COST: 494.425 km
LOAD: 105 vol.
- Osnabrück Hbf | 50 vol.
- Hannover Hbf | 55 vol.
LOAD: 400 vol.
- Nürnberg Hbf | 70 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 70 vol.
- Karlsruhe Hbf | 45 vol.
- Mannheim Hbf | 90 vol.
- Mainz Hbf | 100 vol.
LOAD: 375 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 90 vol.
- Aachen Hbf | 45 vol.
- Köln Hbf | 40 vol.
- Düsseldorf Hbf | 40 vol.
- Dortmund Hbf | 80 vol.
LOAD: 390 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 30 vol.
- Berlin Hbf | 55 vol.
- Dresden Hbf | 70 vol.
- Leipzig Hbf | 75 vol.
LOAD: 105 vol.
- Osnabrück Hbf | 50 vol.
- Hannover Hbf | 55 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, 55, 40, 0, 55, 45, 0, 70, 80, 25, 80, 75, 80, 70, 45, 70, 40, 90, 30, 100, 0, 90, 50, 80] ITERATION Generation: #1 Best cost: 6145.988 | Path: [0, 1, 11, 7, 13, 9, 15, 18, 0, 22, 12, 2, 16, 5, 19, 14, 0, 4, 8, 10, 17, 21, 0, 23, 0] Best cost: 5362.454 | Path: [0, 2, 16, 5, 12, 22, 4, 10, 0, 19, 17, 14, 15, 9, 13, 0, 8, 18, 1, 11, 7, 21, 0, 23, 0] Best cost: 4997.899 | Path: [0, 7, 11, 1, 8, 18, 10, 0, 22, 4, 12, 2, 16, 5, 21, 0, 19, 17, 14, 15, 9, 13, 0, 23, 0] Best cost: 4832.071 | Path: [0, 9, 13, 15, 14, 17, 19, 0, 12, 2, 16, 5, 21, 23, 0, 22, 10, 4, 8, 18, 1, 0, 11, 7, 0] Best cost: 4578.239 | Path: [0, 11, 7, 1, 4, 10, 22, 0, 12, 2, 16, 5, 19, 17, 0, 13, 9, 15, 14, 23, 21, 0, 8, 18, 0] Best cost: 4575.103 | Path: [0, 11, 7, 1, 4, 10, 22, 0, 12, 2, 16, 5, 21, 17, 0, 19, 14, 23, 15, 9, 13, 0, 8, 18, 0] Generation: #4 Best cost: 4398.103 | Path: [0, 13, 9, 15, 14, 17, 19, 0, 12, 2, 16, 5, 21, 23, 0, 11, 7, 1, 8, 18, 10, 0, 22, 4, 0] OPTIMIZING each tour... Current: [[0, 13, 9, 15, 14, 17, 19, 0], [0, 12, 2, 16, 5, 21, 23, 0], [0, 11, 7, 1, 8, 18, 10, 0], [0, 22, 4, 0]] [2] Cost: 1277.142 to 1273.969 | Optimized: [0, 23, 21, 5, 16, 2, 12, 0] [3] Cost: 1467.917 to 1446.488 | Optimized: [0, 10, 8, 18, 1, 7, 11, 0] ACO RESULTS [1/400 vol./1158.619 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Mainz Hbf --> Kassel-Wilhelmshöhe [2/375 vol./1273.969 km] Kassel-Wilhelmshöhe -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [3/390 vol./1446.488 km] Kassel-Wilhelmshöhe -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [4/105 vol./ 494.425 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4373.501 km.