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 (100 vol.)
- Düsseldorf Hbf (70 vol.)
- Hannover Hbf (30 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (45 vol.)
- Leipzig Hbf (70 vol.)
- Nürnberg Hbf (85 vol.)
- Ulm Hbf (35 vol.)
- Köln Hbf (80 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (85 vol.)
- Osnabrück Hbf (80 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1556.668 km
LOAD: 290 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 70 vol.
- Mannheim Hbf | 85 vol.
- Mainz Hbf | 75 vol.
- Würzburg Hbf | 25 vol.
Tour 2
COST: 1174.141 km
LOAD: 295 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 70 vol.
- Hannover Hbf | 30 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 20 vol.
Tour 3
COST: 1364.171 km
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 80 vol.
- Düsseldorf Hbf | 70 vol.
Tour 4
COST: 1943.081 km
LOAD: 260 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 45 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 85 vol.
Tour 5
COST: 836.5 km
LOAD: 80 vol.
- Osnabrück Hbf | 80 vol.
LOAD: 290 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 70 vol.
- Mannheim Hbf | 85 vol.
- Mainz Hbf | 75 vol.
- Würzburg Hbf | 25 vol.
LOAD: 295 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 70 vol.
- Hannover Hbf | 30 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 20 vol.
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 80 vol.
- Düsseldorf Hbf | 70 vol.
LOAD: 260 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 45 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 85 vol.
LOAD: 80 vol.
- Osnabrück Hbf | 80 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: 1215 vol. | Vehicle capacity: 300 vol. Loads: [100, 0, 70, 0, 30, 40, 70, 85, 90, 45, 0, 70, 0, 85, 0, 35, 80, 85, 20, 75, 25, 85, 80, 45] ITERATION Generation: #1 Best cost: 8098.489 | Path: [1, 0, 4, 8, 18, 20, 15, 1, 11, 7, 13, 9, 1, 22, 2, 16, 5, 1, 17, 19, 21, 23, 1, 6, 1] Best cost: 7864.215 | Path: [1, 4, 22, 0, 16, 1, 7, 11, 13, 20, 15, 1, 8, 18, 2, 5, 19, 1, 17, 6, 21, 23, 1, 9, 1] Best cost: 7791.543 | Path: [1, 5, 16, 2, 22, 4, 1, 11, 7, 13, 20, 15, 1, 0, 19, 17, 18, 1, 8, 21, 23, 6, 1, 9, 1] Best cost: 7734.976 | Path: [1, 6, 15, 13, 20, 19, 1, 7, 11, 0, 4, 1, 8, 18, 22, 16, 1, 2, 5, 21, 17, 1, 9, 23, 1] Best cost: 7588.789 | Path: [1, 7, 11, 4, 22, 18, 1, 8, 0, 20, 13, 1, 17, 19, 21, 23, 1, 2, 16, 5, 6, 15, 1, 9, 1] Best cost: 7459.138 | Path: [1, 8, 18, 4, 22, 2, 1, 7, 11, 0, 20, 1, 13, 9, 15, 6, 23, 1, 19, 17, 21, 5, 1, 16, 1] Best cost: 7185.521 | Path: [1, 23, 21, 19, 17, 1, 7, 11, 0, 4, 1, 8, 18, 22, 2, 5, 1, 13, 20, 6, 15, 9, 1, 16, 1] Best cost: 7164.396 | Path: [1, 17, 19, 21, 23, 1, 7, 11, 0, 4, 1, 8, 18, 22, 2, 5, 1, 9, 15, 6, 20, 13, 1, 16, 1] Generation: #2 Best cost: 7119.604 | Path: [1, 7, 11, 0, 4, 1, 8, 18, 22, 2, 5, 1, 13, 20, 6, 15, 9, 1, 19, 17, 21, 23, 1, 16, 1] Best cost: 6994.599 | Path: [1, 23, 21, 19, 17, 1, 7, 11, 4, 22, 18, 1, 8, 2, 16, 5, 1, 13, 20, 6, 15, 9, 1, 0, 1] Generation: #3 Best cost: 6974.679 | Path: [1, 15, 6, 17, 19, 20, 1, 7, 11, 4, 8, 18, 1, 0, 2, 16, 5, 1, 13, 9, 21, 23, 1, 22, 1] OPTIMIZING each tour... Current: [[1, 15, 6, 17, 19, 20, 1], [1, 7, 11, 4, 8, 18, 1], [1, 0, 2, 16, 5, 1], [1, 13, 9, 21, 23, 1], [1, 22, 1]] [3] Cost: 1365.022 to 1364.171 | Optimized: [1, 0, 5, 16, 2, 1] [4] Cost: 2042.348 to 1943.081 | Optimized: [1, 13, 9, 23, 21, 1] ACO RESULTS [1/290 vol./1556.668 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Mainz Hbf -> Würzburg Hbf --> Berlin Hbf [2/295 vol./1174.141 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/290 vol./1364.171 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf [4/260 vol./1943.081 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [5/ 80 vol./ 836.500 km] Berlin Hbf -> Osnabrück Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6874.561 km.