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: 22 customers
- Kassel-Wilhelmshöhe (80 vol.)
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (20 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (30 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (35 vol.)
- Karlsruhe Hbf (90 vol.)
- Ulm Hbf (55 vol.)
- Köln Hbf (75 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (45 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (35 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 1138.071 km
LOAD: 300 vol.
- Leipzig Hbf | 30 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 50 vol.
Tour 2
COST: 1354.595 km
LOAD: 300 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 95 vol.
- Würzburg Hbf | 45 vol.
- Nürnberg Hbf | 35 vol.
- Dresden Hbf | 90 vol.
Tour 3
COST: 1963.179 km
LOAD: 280 vol.
- München Hbf | 20 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 90 vol.
- Freiburg Hbf | 55 vol.
- Saarbrücken Hbf | 30 vol.
Tour 4
COST: 1358.672 km
LOAD: 295 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 65 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 60 vol.
- Osnabrück Hbf | 35 vol.
Tour 5
COST: 785.078 km
LOAD: 80 vol.
- Kassel-Wilhelmshöhe | 80 vol.
LOAD: 300 vol.
- Leipzig Hbf | 30 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 50 vol.
LOAD: 300 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 95 vol.
- Würzburg Hbf | 45 vol.
- Nürnberg Hbf | 35 vol.
- Dresden Hbf | 90 vol.
LOAD: 280 vol.
- München Hbf | 20 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 90 vol.
- Freiburg Hbf | 55 vol.
- Saarbrücken Hbf | 30 vol.
LOAD: 295 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 65 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 60 vol.
- Osnabrück Hbf | 35 vol.
LOAD: 80 vol.
- Kassel-Wilhelmshöhe | 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: 1255 vol. | Vehicle capacity: 300 vol. Loads: [80, 0, 65, 95, 45, 60, 30, 90, 85, 20, 90, 30, 60, 35, 90, 55, 75, 0, 50, 35, 45, 30, 35, 55] ITERATION Generation: #1 Best cost: 8310.437 | Path: [1, 0, 12, 2, 16, 9, 1, 7, 11, 13, 20, 3, 1, 18, 8, 10, 22, 19, 1, 4, 5, 21, 14, 6, 1, 15, 23, 1] Best cost: 8123.305 | Path: [1, 2, 16, 5, 12, 22, 1, 11, 7, 0, 4, 18, 1, 8, 10, 3, 21, 1, 13, 20, 6, 15, 9, 14, 1, 19, 23, 1] Best cost: 7858.839 | Path: [1, 3, 19, 14, 6, 20, 1, 7, 11, 13, 15, 9, 23, 1, 4, 10, 8, 18, 21, 1, 22, 12, 2, 16, 5, 1, 0, 1] Best cost: 7530.171 | Path: [1, 4, 10, 8, 18, 11, 1, 7, 13, 20, 3, 19, 1, 22, 12, 2, 16, 5, 1, 0, 21, 14, 6, 15, 1, 9, 23, 1] Best cost: 7446.978 | Path: [1, 8, 18, 10, 4, 11, 1, 7, 0, 12, 2, 1, 22, 16, 5, 19, 3, 1, 13, 20, 6, 14, 15, 9, 1, 21, 23, 1] Best cost: 7418.856 | Path: [1, 15, 6, 14, 23, 21, 19, 1, 7, 11, 4, 8, 18, 1, 0, 22, 12, 2, 5, 1, 10, 16, 3, 13, 1, 20, 9, 1] Best cost: 7410.540 | Path: [1, 23, 14, 6, 15, 9, 13, 1, 7, 11, 4, 22, 10, 1, 8, 18, 2, 16, 1, 0, 12, 5, 21, 19, 1, 20, 3, 1] Best cost: 7151.531 | Path: [1, 18, 8, 10, 4, 11, 1, 7, 13, 20, 3, 19, 1, 22, 0, 12, 2, 5, 1, 9, 15, 6, 14, 23, 21, 1, 16, 1] Best cost: 6755.883 | Path: [1, 8, 18, 10, 4, 11, 1, 7, 13, 20, 3, 19, 1, 22, 12, 2, 16, 5, 1, 6, 14, 23, 21, 15, 9, 1, 0, 1] Best cost: 6716.480 | Path: [1, 18, 8, 10, 4, 11, 1, 7, 13, 20, 3, 19, 1, 22, 12, 2, 16, 5, 1, 9, 15, 6, 14, 21, 23, 1, 0, 1] Generation: #5 Best cost: 6622.297 | Path: [1, 18, 8, 10, 4, 11, 1, 7, 13, 20, 3, 19, 1, 9, 15, 6, 14, 23, 21, 1, 22, 12, 2, 16, 5, 1, 0, 1] OPTIMIZING each tour... Current: [[1, 18, 8, 10, 4, 11, 1], [1, 7, 13, 20, 3, 19, 1], [1, 9, 15, 6, 14, 23, 21, 1], [1, 22, 12, 2, 16, 5, 1], [1, 0, 1]] [1] Cost: 1146.201 to 1138.071 | Optimized: [1, 11, 4, 10, 8, 18, 1] [2] Cost: 1362.338 to 1354.595 | Optimized: [1, 19, 3, 20, 13, 7, 1] [4] Cost: 1365.501 to 1358.672 | Optimized: [1, 12, 2, 16, 5, 22, 1] ACO RESULTS [1/300 vol./1138.071 km] Berlin Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [2/300 vol./1354.595 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/280 vol./1963.179 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [4/295 vol./1358.672 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Osnabrück Hbf --> Berlin Hbf [5/ 80 vol./ 785.078 km] Berlin Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6599.595 km.