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
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (65 vol.)
- Dresden Hbf (80 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (65 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (80 vol.)
- Nürnberg Hbf (35 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (90 vol.)
- Mannheim Hbf (65 vol.)
- Kiel Hbf (60 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (45 vol.)
- Freiburg Hbf (95 vol.)
Tour 1
COST: 972.057 km
LOAD: 285 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 60 vol.
Tour 2
COST: 1370.455 km
LOAD: 285 vol.
- Dresden Hbf | 80 vol.
- Leipzig Hbf | 50 vol.
- Frankfurt Hbf | 60 vol.
- Würzburg Hbf | 60 vol.
- Nürnberg Hbf | 35 vol.
Tour 3
COST: 1308.428 km
LOAD: 285 vol.
- Dortmund Hbf | 80 vol.
- Düsseldorf Hbf | 35 vol.
- Köln Hbf | 90 vol.
- Aachen Hbf | 80 vol.
Tour 4
COST: 1834.064 km
LOAD: 295 vol.
- Mainz Hbf | 25 vol.
- Mannheim Hbf | 65 vol.
- Saarbrücken Hbf | 45 vol.
- Freiburg Hbf | 95 vol.
- Stuttgart Hbf | 65 vol.
Tour 5
COST: 1346.514 km
LOAD: 105 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 40 vol.
LOAD: 285 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 60 vol.
LOAD: 285 vol.
- Dresden Hbf | 80 vol.
- Leipzig Hbf | 50 vol.
- Frankfurt Hbf | 60 vol.
- Würzburg Hbf | 60 vol.
- Nürnberg Hbf | 35 vol.
LOAD: 285 vol.
- Dortmund Hbf | 80 vol.
- Düsseldorf Hbf | 35 vol.
- Köln Hbf | 90 vol.
- Aachen Hbf | 80 vol.
LOAD: 295 vol.
- Mainz Hbf | 25 vol.
- Mannheim Hbf | 65 vol.
- Saarbrücken Hbf | 45 vol.
- Freiburg Hbf | 95 vol.
- Stuttgart Hbf | 65 vol.
LOAD: 105 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 40 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: 1255 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 35, 60, 50, 80, 65, 80, 80, 65, 95, 50, 80, 35, 0, 40, 90, 65, 60, 25, 60, 45, 0, 95] ITERATION Generation: #1 Best cost: 8417.145 | Path: [1, 2, 16, 5, 12, 1, 7, 11, 4, 10, 19, 1, 8, 18, 20, 13, 9, 1, 3, 17, 6, 15, 21, 1, 23, 1] Best cost: 6963.645 | Path: [1, 4, 10, 8, 18, 1, 7, 11, 13, 20, 6, 1, 19, 3, 17, 21, 23, 1, 12, 2, 16, 5, 1, 15, 9, 1] Best cost: 6899.482 | Path: [1, 4, 10, 8, 18, 1, 7, 11, 13, 20, 3, 1, 12, 2, 16, 5, 1, 17, 19, 21, 23, 6, 1, 9, 15, 1] Best cost: 6874.752 | Path: [1, 12, 2, 16, 5, 1, 11, 7, 13, 20, 3, 1, 4, 10, 8, 18, 1, 19, 17, 21, 23, 6, 1, 15, 9, 1] Best cost: 6874.525 | Path: [1, 4, 10, 8, 18, 1, 11, 7, 13, 20, 3, 1, 2, 16, 5, 12, 1, 19, 17, 21, 23, 6, 1, 9, 15, 1] Generation: #2 Best cost: 6864.438 | Path: [1, 11, 7, 13, 20, 3, 1, 4, 10, 8, 18, 1, 19, 17, 21, 23, 6, 1, 12, 2, 16, 5, 1, 9, 15, 1] Best cost: 6864.438 | Path: [1, 12, 2, 16, 5, 1, 11, 7, 13, 20, 3, 1, 4, 10, 8, 18, 1, 19, 17, 21, 23, 6, 1, 9, 15, 1] Best cost: 6847.408 | Path: [1, 18, 8, 10, 4, 1, 7, 11, 13, 20, 3, 1, 12, 2, 16, 5, 1, 19, 17, 21, 23, 6, 1, 9, 15, 1] Generation: #3 Best cost: 6838.216 | Path: [1, 4, 10, 8, 18, 1, 7, 11, 13, 20, 3, 1, 12, 2, 16, 5, 1, 19, 17, 21, 23, 6, 1, 9, 15, 1] OPTIMIZING each tour... Current: [[1, 4, 10, 8, 18, 1], [1, 7, 11, 13, 20, 3, 1], [1, 12, 2, 16, 5, 1], [1, 19, 17, 21, 23, 6, 1], [1, 9, 15, 1]] [2] Cost: 1377.153 to 1370.455 | Optimized: [1, 7, 11, 3, 20, 13, 1] ACO RESULTS [1/285 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [2/285 vol./1370.455 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf [3/285 vol./1308.428 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf [4/295 vol./1834.064 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Stuttgart Hbf --> Berlin Hbf [5/105 vol./1346.514 km] Berlin Hbf -> München Hbf -> Ulm Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6831.518 km.