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: 300 vol.
ACTIVE: 22 customers
- Kassel-Wilhelmshöhe (65 vol.)
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (20 vol.)
- Stuttgart Hbf (65 vol.)
- Dresden Hbf (40 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (75 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (25 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (95 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (30 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (60 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (20 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 2058.994 km
LOAD: 290 vol.
- Würzburg Hbf | 25 vol.
- Stuttgart Hbf | 65 vol.
- Mannheim Hbf | 60 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 55 vol.
- Saarbrücken Hbf | 20 vol.
- Aachen Hbf | 20 vol.
Tour 2
COST: 1520.359 km
LOAD: 265 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 30 vol.
- Nürnberg Hbf | 95 vol.
- Leipzig Hbf | 25 vol.
- Dresden Hbf | 40 vol.
Tour 3
COST: 972.057 km
LOAD: 255 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 70 vol.
Tour 4
COST: 1175.326 km
LOAD: 210 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 65 vol.
Tour 5
COST: 1338.195 km
LOAD: 285 vol.
- Frankfurt Hbf | 95 vol.
- Mainz Hbf | 95 vol.
- Köln Hbf | 95 vol.
LOAD: 290 vol.
- Würzburg Hbf | 25 vol.
- Stuttgart Hbf | 65 vol.
- Mannheim Hbf | 60 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 55 vol.
- Saarbrücken Hbf | 20 vol.
- Aachen Hbf | 20 vol.
LOAD: 265 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 30 vol.
- Nürnberg Hbf | 95 vol.
- Leipzig Hbf | 25 vol.
- Dresden Hbf | 40 vol.
LOAD: 255 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 70 vol.
LOAD: 210 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 65 vol.
LOAD: 285 vol.
- Frankfurt Hbf | 95 vol.
- Mainz Hbf | 95 vol.
- Köln 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: [1] Berlin Hbf | Number of cities: 24 | Total loads: 1305 vol. | Vehicle capacity: 300 vol. Loads: [65, 0, 80, 95, 50, 20, 65, 40, 80, 75, 55, 25, 65, 95, 45, 30, 95, 60, 70, 95, 25, 20, 0, 55] ITERATION Generation: #1 Best cost: 8483.776 | Path: [1, 0, 12, 2, 5, 21, 14, 1, 7, 11, 4, 10, 8, 20, 1, 18, 15, 6, 17, 23, 1, 3, 19, 16, 1, 13, 9, 1] Best cost: 8247.096 | Path: [1, 2, 16, 5, 12, 21, 1, 7, 11, 20, 3, 19, 1, 18, 8, 10, 4, 14, 1, 13, 9, 15, 6, 1, 0, 17, 23, 1] Best cost: 8242.599 | Path: [1, 5, 2, 16, 12, 11, 1, 7, 13, 20, 3, 14, 1, 18, 8, 10, 4, 21, 1, 0, 19, 17, 6, 1, 9, 15, 23, 1] Best cost: 8216.220 | Path: [1, 6, 14, 17, 19, 20, 1, 7, 11, 0, 4, 10, 12, 1, 8, 18, 16, 5, 21, 1, 13, 9, 15, 23, 1, 3, 2, 1] Best cost: 7865.538 | Path: [1, 17, 14, 6, 15, 9, 20, 1, 11, 7, 13, 19, 21, 5, 1, 4, 10, 8, 18, 1, 0, 12, 2, 23, 1, 3, 16, 1] Best cost: 7371.346 | Path: [1, 20, 13, 6, 14, 17, 1, 11, 7, 9, 15, 23, 21, 5, 1, 8, 18, 10, 4, 1, 0, 12, 2, 1, 3, 19, 16, 1] Generation: #5 Best cost: 7313.440 | Path: [1, 6, 17, 14, 23, 21, 5, 20, 1, 11, 7, 13, 9, 15, 1, 4, 10, 8, 18, 1, 0, 12, 2, 1, 16, 19, 3, 1] OPTIMIZING each tour... Current: [[1, 6, 17, 14, 23, 21, 5, 20, 1], [1, 11, 7, 13, 9, 15, 1], [1, 4, 10, 8, 18, 1], [1, 0, 12, 2, 1], [1, 16, 19, 3, 1]] [1] Cost: 2272.381 to 2058.994 | Optimized: [1, 20, 6, 17, 14, 23, 21, 5, 1] [2] Cost: 1553.708 to 1520.359 | Optimized: [1, 9, 15, 13, 11, 7, 1] [4] Cost: 1176.836 to 1175.326 | Optimized: [1, 12, 2, 0, 1] [5] Cost: 1338.458 to 1338.195 | Optimized: [1, 3, 19, 16, 1] ACO RESULTS [1/290 vol./2058.994 km] Berlin Hbf -> Würzburg Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf --> Berlin Hbf [2/265 vol./1520.359 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/255 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/210 vol./1175.326 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [5/285 vol./1338.195 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Köln Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7064.931 km.