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
- Düsseldorf Hbf (75 vol.)
- Frankfurt Hbf (35 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (100 vol.)
- Leipzig Hbf (20 vol.)
- Nürnberg Hbf (75 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1984.97 km
LOAD: 295 vol.
- Würzburg Hbf | 30 vol.
- Frankfurt Hbf | 35 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 25 vol.
- Saarbrücken Hbf | 20 vol.
- Freiburg Hbf | 70 vol.
- Ulm Hbf | 20 vol.
- Nürnberg Hbf | 75 vol.
Tour 2
COST: 1351.092 km
LOAD: 290 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 70 vol.
- Düsseldorf Hbf | 75 vol.
- Osnabrück Hbf | 20 vol.
- Hannover Hbf | 85 vol.
Tour 3
COST: 1165.88 km
LOAD: 245 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 20 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 50 vol.
Tour 4
COST: 1430.64 km
LOAD: 195 vol.
- München Hbf | 100 vol.
- Stuttgart Hbf | 95 vol.
LOAD: 295 vol.
- Würzburg Hbf | 30 vol.
- Frankfurt Hbf | 35 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 25 vol.
- Saarbrücken Hbf | 20 vol.
- Freiburg Hbf | 70 vol.
- Ulm Hbf | 20 vol.
- Nürnberg Hbf | 75 vol.
LOAD: 290 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 70 vol.
- Düsseldorf Hbf | 75 vol.
- Osnabrück Hbf | 20 vol.
- Hannover Hbf | 85 vol.
LOAD: 245 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 20 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 50 vol.
LOAD: 195 vol.
- München Hbf | 100 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: 1025 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 75, 35, 85, 40, 95, 95, 80, 100, 0, 20, 0, 75, 0, 20, 70, 25, 50, 20, 30, 20, 20, 70] ITERATION Generation: #1 Best cost: 7427.573 | Path: [1, 2, 16, 5, 3, 19, 17, 21, 1, 7, 11, 13, 20, 15, 22, 1, 4, 18, 8, 23, 1, 9, 6, 1] Best cost: 6718.202 | Path: [1, 3, 19, 17, 6, 15, 9, 1, 7, 11, 4, 22, 2, 1, 8, 18, 16, 5, 21, 20, 1, 13, 23, 1] Best cost: 6497.304 | Path: [1, 6, 15, 9, 13, 1, 7, 11, 4, 8, 22, 1, 20, 3, 19, 17, 21, 23, 5, 18, 1, 2, 16, 1] Best cost: 6480.172 | Path: [1, 17, 3, 19, 21, 23, 6, 15, 1, 11, 7, 16, 2, 5, 1, 8, 18, 4, 22, 20, 1, 13, 9, 1] Best cost: 6416.430 | Path: [1, 3, 19, 17, 23, 6, 15, 20, 1, 8, 18, 4, 22, 5, 21, 1, 11, 7, 13, 9, 1, 16, 2, 1] Best cost: 6414.659 | Path: [1, 3, 19, 17, 21, 23, 6, 15, 1, 11, 7, 13, 9, 1, 8, 18, 4, 22, 5, 1, 20, 2, 16, 1] Best cost: 6396.101 | Path: [1, 13, 20, 3, 19, 17, 21, 23, 15, 1, 11, 7, 4, 22, 8, 1, 18, 5, 16, 2, 1, 9, 6, 1] Best cost: 5996.815 | Path: [1, 13, 20, 3, 19, 17, 21, 23, 15, 1, 4, 22, 2, 16, 5, 1, 7, 11, 8, 18, 1, 9, 6, 1] OPTIMIZING each tour... Current: [[1, 13, 20, 3, 19, 17, 21, 23, 15, 1], [1, 4, 22, 2, 16, 5, 1], [1, 7, 11, 8, 18, 1], [1, 9, 6, 1]] [1] Cost: 2041.902 to 1984.970 | Optimized: [1, 20, 3, 19, 17, 21, 23, 15, 13, 1] [2] Cost: 1358.393 to 1351.092 | Optimized: [1, 5, 16, 2, 22, 4, 1] ACO RESULTS [1/295 vol./1984.970 km] Berlin Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Ulm Hbf -> Nürnberg Hbf --> Berlin Hbf [2/290 vol./1351.092 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [3/245 vol./1165.880 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/195 vol./1430.640 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5932.582 km.