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 (60 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (50 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (90 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (30 vol.)
- Köln Hbf (70 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (45 vol.)
- Würzburg Hbf (65 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1595.738 km
LOAD: 290 vol.
- Mainz Hbf | 45 vol.
- Frankfurt Hbf | 55 vol.
- Würzburg Hbf | 65 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 100 vol.
Tour 2
COST: 1936.138 km
LOAD: 275 vol.
- Dresden Hbf | 50 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 60 vol.
Tour 3
COST: 947.647 km
LOAD: 285 vol.
- Hannover Hbf | 45 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 65 vol.
Tour 4
COST: 1364.171 km
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Aachen Hbf | 70 vol.
- Köln Hbf | 70 vol.
- Düsseldorf Hbf | 95 vol.
Tour 5
COST: 701.943 km
LOAD: 80 vol.
- Kiel Hbf | 80 vol.
LOAD: 290 vol.
- Mainz Hbf | 45 vol.
- Frankfurt Hbf | 55 vol.
- Würzburg Hbf | 65 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 100 vol.
LOAD: 275 vol.
- Dresden Hbf | 50 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 60 vol.
LOAD: 285 vol.
- Hannover Hbf | 45 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 65 vol.
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Aachen Hbf | 70 vol.
- Köln Hbf | 70 vol.
- Düsseldorf Hbf | 95 vol.
LOAD: 80 vol.
- Kiel 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: 1225 vol. | Vehicle capacity: 300 vol. Loads: [60, 0, 95, 55, 45, 70, 30, 50, 65, 100, 90, 0, 0, 25, 80, 30, 70, 0, 80, 45, 65, 60, 85, 25] ITERATION Generation: #1 Best cost: 7967.057 | Path: [1, 0, 22, 4, 10, 1, 7, 13, 20, 3, 19, 21, 1, 8, 18, 2, 6, 15, 1, 16, 5, 14, 23, 1, 9, 1] Best cost: 7417.823 | Path: [1, 2, 16, 5, 19, 1, 7, 13, 20, 3, 14, 23, 1, 8, 18, 10, 4, 1, 0, 22, 21, 6, 15, 1, 9, 1] Best cost: 7401.288 | Path: [1, 15, 6, 14, 23, 21, 19, 13, 1, 7, 0, 22, 10, 1, 8, 18, 4, 5, 1, 20, 3, 16, 2, 1, 9, 1] Best cost: 7318.946 | Path: [1, 21, 14, 6, 15, 9, 1, 7, 13, 20, 3, 19, 0, 1, 8, 18, 10, 4, 1, 22, 2, 16, 23, 1, 5, 1] Best cost: 7274.240 | Path: [1, 23, 14, 6, 15, 9, 13, 1, 7, 20, 3, 19, 21, 1, 4, 10, 22, 0, 1, 8, 18, 2, 1, 5, 16, 1] Best cost: 6948.863 | Path: [1, 15, 6, 14, 23, 21, 19, 13, 1, 4, 10, 8, 18, 1, 7, 20, 3, 16, 0, 1, 2, 5, 22, 1, 9, 1] Best cost: 6919.575 | Path: [1, 6, 14, 19, 3, 20, 13, 1, 7, 15, 9, 23, 21, 1, 4, 10, 8, 18, 1, 5, 16, 2, 0, 1, 22, 1] Best cost: 6546.488 | Path: [1, 19, 3, 20, 13, 9, 1, 7, 15, 6, 14, 23, 21, 1, 4, 22, 10, 8, 1, 0, 2, 16, 5, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 19, 3, 20, 13, 9, 1], [1, 7, 15, 6, 14, 23, 21, 1], [1, 4, 22, 10, 8, 1], [1, 0, 2, 16, 5, 1], [1, 18, 1]] [4] Cost: 1365.022 to 1364.171 | Optimized: [1, 0, 5, 16, 2, 1] ACO RESULTS [1/290 vol./1595.738 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf [2/275 vol./1936.138 km] Berlin Hbf -> Dresden Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [3/285 vol./ 947.647 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [4/295 vol./1364.171 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf [5/ 80 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6545.637 km.