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: 20 customers
- Kassel-Wilhelmshöhe (60 vol.)
- Düsseldorf Hbf (50 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (80 vol.)
- Leipzig Hbf (85 vol.)
- Dortmund Hbf (75 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (70 vol.)
- Ulm Hbf (50 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (55 vol.)
- Kiel Hbf (100 vol.)
- Würzburg Hbf (35 vol.)
- Saarbrücken Hbf (55 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1371.845 km
LOAD: 295 vol.
- Frankfurt Hbf | 60 vol.
- Würzburg Hbf | 35 vol.
- Nürnberg Hbf | 25 vol.
- Leipzig Hbf | 85 vol.
- Dresden Hbf | 90 vol.
Tour 2
COST: 1173.016 km
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Hannover Hbf | 25 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 100 vol.
Tour 3
COST: 1308.428 km
LOAD: 295 vol.
- Dortmund Hbf | 75 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 100 vol.
Tour 4
COST: 1751.636 km
LOAD: 255 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 70 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 55 vol.
Tour 5
COST: 1447.27 km
LOAD: 225 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 50 vol.
- Stuttgart Hbf | 95 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 60 vol.
- Würzburg Hbf | 35 vol.
- Nürnberg Hbf | 25 vol.
- Leipzig Hbf | 85 vol.
- Dresden Hbf | 90 vol.
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Hannover Hbf | 25 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 100 vol.
LOAD: 295 vol.
- Dortmund Hbf | 75 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 100 vol.
LOAD: 255 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 70 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 55 vol.
LOAD: 225 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 50 vol.
- Stuttgart 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: 1355 vol. | Vehicle capacity: 300 vol. Loads: [60, 0, 50, 60, 25, 100, 95, 90, 100, 80, 0, 85, 75, 25, 70, 50, 70, 55, 100, 0, 35, 55, 0, 75] ITERATION Generation: #1 Best cost: 7859.969 | Path: [1, 0, 3, 17, 14, 21, 1, 11, 7, 13, 20, 15, 1, 4, 8, 18, 2, 1, 12, 16, 5, 1, 23, 6, 9, 1] Best cost: 7690.818 | Path: [1, 2, 16, 5, 12, 1, 11, 7, 13, 20, 3, 1, 4, 8, 18, 0, 1, 14, 17, 6, 15, 1, 9, 21, 23, 1] Best cost: 7446.523 | Path: [1, 3, 17, 14, 6, 1, 11, 7, 20, 13, 15, 1, 8, 18, 4, 0, 1, 12, 2, 16, 5, 1, 9, 23, 21, 1] Best cost: 7398.578 | Path: [1, 12, 2, 16, 5, 1, 11, 7, 13, 20, 3, 1, 4, 8, 18, 0, 1, 9, 15, 6, 14, 1, 17, 21, 23, 1] Best cost: 7355.328 | Path: [1, 17, 14, 6, 15, 13, 1, 11, 7, 20, 3, 4, 1, 8, 18, 0, 1, 12, 2, 16, 5, 1, 9, 23, 21, 1] Best cost: 7261.859 | Path: [1, 5, 2, 16, 12, 1, 8, 18, 4, 0, 1, 7, 11, 13, 20, 3, 1, 9, 15, 6, 14, 1, 17, 21, 23, 1] Best cost: 7231.528 | Path: [1, 8, 18, 4, 0, 1, 7, 11, 13, 20, 3, 1, 5, 16, 2, 12, 1, 9, 15, 6, 14, 1, 17, 21, 23, 1] Best cost: 7205.806 | Path: [1, 8, 18, 4, 0, 1, 7, 11, 13, 20, 3, 1, 12, 2, 16, 5, 1, 23, 14, 17, 21, 1, 9, 15, 6, 1] Best cost: 7196.894 | Path: [1, 0, 4, 8, 18, 1, 7, 11, 13, 20, 3, 1, 12, 2, 16, 5, 1, 9, 15, 6, 14, 1, 17, 21, 23, 1] Generation: #2 Best cost: 7171.127 | Path: [1, 13, 20, 3, 17, 14, 21, 1, 7, 11, 0, 4, 1, 8, 18, 12, 1, 9, 15, 6, 23, 1, 2, 16, 5, 1] Generation: #7 Best cost: 7168.193 | Path: [1, 11, 7, 13, 9, 1, 8, 18, 4, 0, 1, 17, 14, 6, 15, 1, 12, 2, 16, 5, 1, 20, 3, 21, 23, 1] Generation: #8 Best cost: 7120.668 | Path: [1, 11, 7, 13, 20, 3, 1, 8, 18, 4, 0, 1, 12, 2, 16, 5, 1, 21, 23, 14, 17, 1, 9, 15, 6, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 13, 20, 3, 1], [1, 8, 18, 4, 0, 1], [1, 12, 2, 16, 5, 1], [1, 21, 23, 14, 17, 1], [1, 9, 15, 6, 1]] [1] Cost: 1403.375 to 1371.845 | Optimized: [1, 3, 20, 13, 11, 7, 1] [2] Cost: 1205.415 to 1173.016 | Optimized: [1, 0, 4, 8, 18, 1] [4] Cost: 1756.180 to 1751.636 | Optimized: [1, 17, 14, 23, 21, 1] ACO RESULTS [1/295 vol./1371.845 km] Berlin Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [2/285 vol./1173.016 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/295 vol./1308.428 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf [4/255 vol./1751.636 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [5/225 vol./1447.270 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7052.195 km.