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: 16 customers
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (90 vol.)
- Aachen Hbf (50 vol.)
- Dresden Hbf (25 vol.)
- München Hbf (50 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (25 vol.)
- Nürnberg Hbf (90 vol.)
- Karlsruhe Hbf (60 vol.)
- Köln Hbf (40 vol.)
- Mannheim Hbf (40 vol.)
- Würzburg Hbf (35 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (25 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1511.394 km
LOAD: 285 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 50 vol.
- Frankfurt Hbf | 45 vol.
- Mannheim Hbf | 40 vol.
- Würzburg Hbf | 35 vol.
- Nürnberg Hbf | 90 vol.
Tour 2
COST: 2132.297 km
LOAD: 295 vol.
- München Hbf | 50 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 50 vol.
- Saarbrücken Hbf | 20 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 40 vol.
- Dortmund Hbf | 25 vol.
Tour 3
COST: 931.848 km
LOAD: 150 vol.
- Hannover Hbf | 90 vol.
- Osnabrück Hbf | 25 vol.
- Bremen Hbf | 35 vol.
LOAD: 285 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 50 vol.
- Frankfurt Hbf | 45 vol.
- Mannheim Hbf | 40 vol.
- Würzburg Hbf | 35 vol.
- Nürnberg Hbf | 90 vol.
LOAD: 295 vol.
- München Hbf | 50 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 50 vol.
- Saarbrücken Hbf | 20 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 40 vol.
- Dortmund Hbf | 25 vol.
LOAD: 150 vol.
- Hannover Hbf | 90 vol.
- Osnabrück Hbf | 25 vol.
- Bremen Hbf | 35 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: 730 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 0, 45, 90, 50, 0, 25, 0, 50, 35, 50, 25, 90, 60, 0, 40, 40, 0, 0, 35, 20, 25, 50] ITERATION Generation: #1 Best cost: 5745.378 | Path: [1, 3, 20, 13, 9, 14, 21, 1, 11, 7, 4, 10, 22, 12, 16, 1, 17, 23, 5, 1] Best cost: 5162.728 | Path: [1, 4, 10, 22, 12, 16, 5, 21, 1, 7, 11, 13, 20, 3, 17, 1, 14, 23, 9, 1] Best cost: 5005.054 | Path: [1, 21, 17, 14, 23, 3, 20, 9, 1, 11, 7, 13, 16, 5, 12, 1, 4, 22, 10, 1] Best cost: 4945.221 | Path: [1, 12, 16, 5, 21, 14, 17, 3, 1, 11, 7, 13, 20, 9, 23, 1, 4, 10, 22, 1] Best cost: 4893.653 | Path: [1, 5, 16, 12, 22, 4, 10, 7, 1, 11, 3, 17, 14, 23, 21, 20, 1, 13, 9, 1] Best cost: 4869.869 | Path: [1, 12, 16, 5, 22, 10, 4, 7, 1, 11, 20, 3, 17, 14, 21, 23, 1, 13, 9, 1] Best cost: 4791.644 | Path: [1, 12, 16, 5, 21, 17, 14, 23, 1, 11, 7, 20, 3, 13, 9, 1, 4, 10, 22, 1] Best cost: 4775.692 | Path: [1, 16, 5, 12, 22, 10, 4, 7, 1, 11, 20, 3, 17, 14, 23, 21, 1, 13, 9, 1] Best cost: 4768.711 | Path: [1, 16, 5, 12, 22, 10, 4, 7, 1, 11, 3, 17, 14, 23, 21, 20, 1, 13, 9, 1] Best cost: 4713.413 | Path: [1, 11, 7, 13, 20, 3, 17, 1, 12, 16, 5, 21, 14, 23, 9, 1, 4, 10, 22, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 13, 20, 3, 17, 1], [1, 12, 16, 5, 21, 14, 23, 9, 1], [1, 4, 10, 22, 1]] [1] Cost: 1559.477 to 1511.394 | Optimized: [1, 7, 11, 3, 17, 20, 13, 1] [2] Cost: 2206.445 to 2132.297 | Optimized: [1, 9, 14, 23, 21, 5, 16, 12, 1] [3] Cost: 947.491 to 931.848 | Optimized: [1, 4, 22, 10, 1] ACO RESULTS [1/285 vol./1511.394 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf [2/295 vol./2132.297 km] Berlin Hbf -> München Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Dortmund Hbf --> Berlin Hbf [3/150 vol./ 931.848 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4575.539 km.