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 (85 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (75 vol.)
- Hannover Hbf (20 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (80 vol.)
- Hamburg Hbf (50 vol.)
- München Hbf (85 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (75 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (35 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (45 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (40 vol.)
Tour 1
COST: 1780.142 km
LOAD: 295 vol.
- Hannover Hbf | 20 vol.
- Mannheim Hbf | 25 vol.
- Saarbrücken Hbf | 40 vol.
- Karlsruhe Hbf | 35 vol.
- Stuttgart Hbf | 95 vol.
- Ulm Hbf | 80 vol.
Tour 2
COST: 1245.897 km
LOAD: 285 vol.
- Dresden Hbf | 80 vol.
- Leipzig Hbf | 75 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 45 vol.
Tour 3
COST: 1204.747 km
LOAD: 255 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 75 vol.
- Kassel-Wilhelmshöhe | 85 vol.
Tour 4
COST: 1303.404 km
LOAD: 265 vol.
- Aachen Hbf | 75 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 95 vol.
Tour 5
COST: 1345.202 km
LOAD: 270 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 85 vol.
LOAD: 295 vol.
- Hannover Hbf | 20 vol.
- Mannheim Hbf | 25 vol.
- Saarbrücken Hbf | 40 vol.
- Karlsruhe Hbf | 35 vol.
- Stuttgart Hbf | 95 vol.
- Ulm Hbf | 80 vol.
LOAD: 285 vol.
- Dresden Hbf | 80 vol.
- Leipzig Hbf | 75 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 45 vol.
LOAD: 255 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 75 vol.
- Kassel-Wilhelmshöhe | 85 vol.
LOAD: 265 vol.
- Aachen Hbf | 75 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 95 vol.
LOAD: 270 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 85 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: 1370 vol. | Vehicle capacity: 300 vol. Loads: [85, 0, 95, 75, 20, 75, 95, 80, 50, 85, 35, 75, 0, 100, 35, 80, 95, 25, 45, 95, 85, 40, 0, 0] ITERATION Generation: #1 Best cost: 8352.681 | Path: [1, 0, 3, 19, 17, 4, 1, 7, 11, 13, 14, 1, 8, 10, 18, 16, 5, 1, 21, 2, 20, 15, 1, 9, 6, 1] Best cost: 7943.675 | Path: [1, 2, 16, 5, 17, 1, 11, 7, 13, 14, 1, 4, 10, 8, 18, 0, 21, 1, 20, 3, 19, 1, 6, 15, 9, 1] Best cost: 7578.047 | Path: [1, 3, 19, 17, 14, 21, 4, 1, 11, 7, 13, 10, 1, 8, 18, 0, 20, 1, 2, 16, 5, 1, 9, 15, 6, 1] Best cost: 7176.002 | Path: [1, 6, 14, 17, 19, 21, 1, 7, 11, 4, 10, 8, 1, 18, 0, 20, 3, 1, 13, 9, 15, 1, 16, 2, 5, 1] Best cost: 7151.334 | Path: [1, 13, 20, 17, 14, 21, 1, 7, 11, 4, 10, 8, 1, 18, 3, 19, 0, 1, 6, 15, 9, 1, 16, 2, 5, 1] Best cost: 6997.009 | Path: [1, 15, 6, 14, 17, 21, 4, 1, 7, 11, 10, 8, 18, 1, 0, 3, 19, 1, 16, 2, 5, 1, 13, 20, 9, 1] OPTIMIZING each tour... Current: [[1, 15, 6, 14, 17, 21, 4, 1], [1, 7, 11, 10, 8, 18, 1], [1, 0, 3, 19, 1], [1, 16, 2, 5, 1], [1, 13, 20, 9, 1]] [1] Cost: 1806.982 to 1780.142 | Optimized: [1, 4, 17, 21, 14, 6, 15, 1] [3] Cost: 1205.647 to 1204.747 | Optimized: [1, 19, 3, 0, 1] [4] Cost: 1323.780 to 1303.404 | Optimized: [1, 5, 16, 2, 1] [5] Cost: 1414.703 to 1345.202 | Optimized: [1, 20, 13, 9, 1] ACO RESULTS [1/295 vol./1780.142 km] Berlin Hbf -> Hannover Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [2/285 vol./1245.897 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/255 vol./1204.747 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/265 vol./1303.404 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf [5/270 vol./1345.202 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6879.392 km.