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: 18 customers
- Kassel-Wilhelmshöhe (45 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (50 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (55 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (55 vol.)
- Dortmund Hbf (85 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (45 vol.)
- Köln Hbf (100 vol.)
- Mannheim Hbf (30 vol.)
- Kiel Hbf (85 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (35 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1679.344 km
LOAD: 300 vol.
- Mannheim Hbf | 30 vol.
- Saarbrücken Hbf | 35 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 100 vol.
- Dortmund Hbf | 85 vol.
Tour 2
COST: 1138.071 km
LOAD: 285 vol.
- Leipzig Hbf | 55 vol.
- Hannover Hbf | 65 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 85 vol.
Tour 3
COST: 1919.405 km
LOAD: 285 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 45 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 20 vol.
- Mainz Hbf | 95 vol.
- Würzburg Hbf | 25 vol.
Tour 4
COST: 984.722 km
LOAD: 130 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Osnabrück Hbf | 85 vol.
LOAD: 300 vol.
- Mannheim Hbf | 30 vol.
- Saarbrücken Hbf | 35 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 100 vol.
- Dortmund Hbf | 85 vol.
LOAD: 285 vol.
- Leipzig Hbf | 55 vol.
- Hannover Hbf | 65 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 85 vol.
LOAD: 285 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 45 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 20 vol.
- Mainz Hbf | 95 vol.
- Würzburg Hbf | 25 vol.
LOAD: 130 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Osnabrück Hbf | 85 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: 1000 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 0, 0, 65, 50, 0, 0, 35, 55, 45, 55, 85, 0, 45, 45, 100, 30, 85, 95, 25, 35, 85, 20] ITERATION Generation: #1 Best cost: 6807.155 | Path: [1, 0, 12, 16, 5, 23, 1, 11, 4, 22, 10, 8, 1, 18, 20, 19, 17, 14, 1, 9, 15, 21, 1] Best cost: 6742.313 | Path: [1, 8, 10, 4, 22, 0, 20, 1, 11, 17, 14, 15, 9, 23, 21, 1, 12, 16, 5, 1, 18, 19, 1] Best cost: 6686.254 | Path: [1, 9, 15, 14, 17, 19, 20, 1, 11, 4, 10, 22, 0, 1, 8, 18, 12, 5, 21, 1, 16, 23, 1] Best cost: 6245.992 | Path: [1, 11, 20, 19, 17, 14, 23, 1, 18, 8, 10, 22, 0, 1, 4, 12, 16, 5, 1, 15, 9, 21, 1] Best cost: 6199.866 | Path: [1, 8, 18, 10, 22, 0, 1, 11, 20, 19, 17, 14, 15, 1, 4, 12, 16, 5, 1, 9, 21, 23, 1] Best cost: 6187.369 | Path: [1, 20, 19, 17, 14, 21, 23, 15, 1, 11, 4, 10, 8, 18, 1, 0, 12, 16, 5, 1, 22, 9, 1] Best cost: 5842.714 | Path: [1, 9, 15, 17, 14, 19, 20, 1, 11, 4, 10, 8, 18, 1, 12, 16, 5, 21, 23, 1, 0, 22, 1] Best cost: 5730.929 | Path: [1, 12, 16, 5, 21, 17, 1, 11, 4, 10, 8, 18, 1, 20, 19, 14, 23, 15, 9, 1, 22, 0, 1] Generation: #2 Best cost: 5729.923 | Path: [1, 12, 16, 5, 21, 17, 1, 11, 4, 10, 8, 18, 1, 20, 19, 14, 23, 15, 9, 1, 0, 22, 1] OPTIMIZING each tour... Current: [[1, 12, 16, 5, 21, 17, 1], [1, 11, 4, 10, 8, 18, 1], [1, 20, 19, 14, 23, 15, 9, 1], [1, 0, 22, 1]] [1] Cost: 1681.351 to 1679.344 | Optimized: [1, 17, 21, 5, 16, 12, 1] [3] Cost: 1925.779 to 1919.405 | Optimized: [1, 9, 15, 14, 23, 19, 20, 1] ACO RESULTS [1/300 vol./1679.344 km] Berlin Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Dortmund Hbf --> Berlin Hbf [2/285 vol./1138.071 km] Berlin Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/285 vol./1919.405 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Mainz Hbf -> Würzburg Hbf --> Berlin Hbf [4/130 vol./ 984.722 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5721.542 km.