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: 14 customers
- Kassel-Wilhelmshöhe (80 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (45 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (60 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (40 vol.)
- Mannheim Hbf (95 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (85 vol.)
- Osnabrück Hbf (50 vol.)
Tour 1
COST: 1763.124 km
LOAD: 300 vol.
- Osnabrück Hbf | 50 vol.
- Dortmund Hbf | 50 vol.
- Aachen Hbf | 45 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 95 vol.
- Karlsruhe Hbf | 40 vol.
Tour 2
COST: 1424.314 km
LOAD: 290 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 60 vol.
- Dresden Hbf | 45 vol.
Tour 3
COST: 1173.016 km
LOAD: 240 vol.
- Kassel-Wilhelmshöhe | 80 vol.
- Hannover Hbf | 40 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 100 vol.
LOAD: 300 vol.
- Osnabrück Hbf | 50 vol.
- Dortmund Hbf | 50 vol.
- Aachen Hbf | 45 vol.
- Mainz Hbf | 20 vol.
- Mannheim Hbf | 95 vol.
- Karlsruhe Hbf | 40 vol.
LOAD: 290 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 60 vol.
- Dresden Hbf | 45 vol.
LOAD: 240 vol.
- Kassel-Wilhelmshöhe | 80 vol.
- Hannover Hbf | 40 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 100 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: 830 vol. | Vehicle capacity: 300 vol. Loads: [80, 0, 0, 0, 40, 45, 0, 45, 20, 60, 0, 0, 50, 100, 40, 0, 0, 95, 100, 20, 85, 0, 50, 0] ITERATION Generation: #1 Best cost: 5033.973 | Path: [1, 0, 4, 22, 12, 5, 19, 1, 7, 20, 13, 9, 1, 8, 18, 17, 14, 1] Best cost: 4788.333 | Path: [1, 4, 22, 12, 5, 19, 17, 1, 8, 18, 0, 20, 1, 7, 13, 9, 14, 1] Best cost: 4558.686 | Path: [1, 22, 12, 5, 19, 17, 14, 1, 8, 18, 4, 0, 7, 1, 13, 20, 9, 1] Best cost: 4452.406 | Path: [1, 18, 8, 4, 22, 0, 1, 7, 9, 13, 20, 1, 12, 5, 19, 17, 14, 1] Best cost: 4402.423 | Path: [1, 22, 12, 5, 19, 17, 14, 1, 7, 20, 13, 9, 1, 8, 18, 4, 0, 1] Generation: #3 Best cost: 4374.029 | Path: [1, 22, 12, 5, 19, 17, 14, 1, 7, 9, 13, 20, 1, 18, 8, 4, 0, 1] OPTIMIZING each tour... Current: [[1, 22, 12, 5, 19, 17, 14, 1], [1, 7, 9, 13, 20, 1], [1, 18, 8, 4, 0, 1]] [2] Cost: 1428.520 to 1424.314 | Optimized: [1, 20, 13, 9, 7, 1] [3] Cost: 1182.385 to 1173.016 | Optimized: [1, 0, 4, 8, 18, 1] ACO RESULTS [1/300 vol./1763.124 km] Berlin Hbf -> Osnabrück Hbf -> Dortmund Hbf -> Aachen Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf --> Berlin Hbf [2/290 vol./1424.314 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Dresden Hbf --> Berlin Hbf [3/240 vol./1173.016 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4360.454 km.