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: 19 customers
- Kassel-Wilhelmshöhe (75 vol.)
- Düsseldorf Hbf (75 vol.)
- Frankfurt Hbf (25 vol.)
- Hannover Hbf (55 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (30 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (90 vol.)
- Bremen Hbf (70 vol.)
- Leipzig Hbf (30 vol.)
- Dortmund Hbf (35 vol.)
- Nürnberg Hbf (90 vol.)
- Karlsruhe Hbf (75 vol.)
- Mannheim Hbf (30 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (65 vol.)
- Saarbrücken Hbf (45 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1446.647 km
LOAD: 290 vol.
- Frankfurt Hbf | 25 vol.
- Mainz Hbf | 100 vol.
- Mannheim Hbf | 30 vol.
- Karlsruhe Hbf | 75 vol.
- Stuttgart Hbf | 60 vol.
Tour 2
COST: 1312.378 km
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Würzburg Hbf | 65 vol.
- Nürnberg Hbf | 90 vol.
- Leipzig Hbf | 30 vol.
- Dresden Hbf | 30 vol.
Tour 3
COST: 972.057 km
LOAD: 295 vol.
- Hannover Hbf | 55 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 90 vol.
Tour 4
COST: 2035.318 km
LOAD: 295 vol.
- München Hbf | 90 vol.
- Freiburg Hbf | 50 vol.
- Saarbrücken Hbf | 45 vol.
- Düsseldorf Hbf | 75 vol.
- Dortmund Hbf | 35 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 25 vol.
- Mainz Hbf | 100 vol.
- Mannheim Hbf | 30 vol.
- Karlsruhe Hbf | 75 vol.
- Stuttgart Hbf | 60 vol.
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Würzburg Hbf | 65 vol.
- Nürnberg Hbf | 90 vol.
- Leipzig Hbf | 30 vol.
- Dresden Hbf | 30 vol.
LOAD: 295 vol.
- Hannover Hbf | 55 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 90 vol.
LOAD: 295 vol.
- München Hbf | 90 vol.
- Freiburg Hbf | 50 vol.
- Saarbrücken Hbf | 45 vol.
- Düsseldorf Hbf | 75 vol.
- Dortmund Hbf | 35 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: 1170 vol. | Vehicle capacity: 300 vol. Loads: [75, 0, 75, 25, 55, 0, 60, 30, 80, 90, 70, 30, 35, 90, 75, 0, 0, 30, 90, 100, 65, 45, 0, 50] ITERATION Generation: #1 Best cost: 7083.603 | Path: [1, 0, 3, 19, 17, 21, 1, 11, 7, 13, 20, 6, 1, 8, 18, 10, 4, 1, 9, 14, 23, 2, 1, 12, 1] Best cost: 6297.679 | Path: [1, 3, 19, 17, 14, 6, 1, 7, 11, 13, 20, 0, 1, 18, 8, 10, 4, 1, 23, 21, 2, 12, 9, 1] Best cost: 5835.297 | Path: [1, 6, 14, 17, 19, 3, 1, 11, 7, 13, 20, 0, 1, 8, 18, 10, 4, 1, 12, 2, 21, 23, 9, 1] Best cost: 5797.528 | Path: [1, 3, 19, 17, 14, 6, 1, 11, 7, 13, 20, 0, 1, 4, 10, 8, 18, 1, 9, 23, 21, 2, 12, 1] Generation: #3 Best cost: 5789.054 | Path: [1, 6, 14, 17, 19, 3, 1, 7, 11, 13, 20, 0, 1, 4, 10, 8, 18, 1, 12, 2, 21, 23, 9, 1] OPTIMIZING each tour... Current: [[1, 6, 14, 17, 19, 3, 1], [1, 7, 11, 13, 20, 0, 1], [1, 4, 10, 8, 18, 1], [1, 12, 2, 21, 23, 9, 1]] [1] Cost: 1448.789 to 1446.647 | Optimized: [1, 3, 19, 17, 14, 6, 1] [2] Cost: 1317.284 to 1312.378 | Optimized: [1, 0, 20, 13, 11, 7, 1] [4] Cost: 2050.924 to 2035.318 | Optimized: [1, 9, 23, 21, 2, 12, 1] ACO RESULTS [1/290 vol./1446.647 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf --> Berlin Hbf [2/290 vol./1312.378 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/295 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/295 vol./2035.318 km] Berlin Hbf -> München Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5766.400 km.