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: 15 customers
- Kassel-Wilhelmshöhe (60 vol.)
- Düsseldorf Hbf (20 vol.)
- Frankfurt Hbf (35 vol.)
- Hannover Hbf (60 vol.)
- Aachen Hbf (55 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (30 vol.)
- Dortmund Hbf (70 vol.)
- Nürnberg Hbf (30 vol.)
- Mainz Hbf (40 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (75 vol.)
- Osnabrück Hbf (25 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1551.906 km
LOAD: 290 vol.
- Düsseldorf Hbf | 20 vol.
- Mainz Hbf | 40 vol.
- Frankfurt Hbf | 35 vol.
- Würzburg Hbf | 90 vol.
- Nürnberg Hbf | 30 vol.
- Dresden Hbf | 75 vol.
Tour 2
COST: 2105.464 km
LOAD: 295 vol.
- München Hbf | 30 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 75 vol.
- Aachen Hbf | 55 vol.
- Dortmund Hbf | 70 vol.
Tour 3
COST: 1138.965 km
LOAD: 165 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Osnabrück Hbf | 25 vol.
- Hannover Hbf | 60 vol.
- Hamburg Hbf | 20 vol.
LOAD: 290 vol.
- Düsseldorf Hbf | 20 vol.
- Mainz Hbf | 40 vol.
- Frankfurt Hbf | 35 vol.
- Würzburg Hbf | 90 vol.
- Nürnberg Hbf | 30 vol.
- Dresden Hbf | 75 vol.
LOAD: 295 vol.
- München Hbf | 30 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 75 vol.
- Aachen Hbf | 55 vol.
- Dortmund Hbf | 70 vol.
LOAD: 165 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Osnabrück Hbf | 25 vol.
- Hannover Hbf | 60 vol.
- Hamburg Hbf | 20 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: 750 vol. | Vehicle capacity: 300 vol. Loads: [60, 0, 20, 35, 60, 55, 0, 75, 20, 30, 0, 0, 70, 30, 0, 0, 0, 0, 0, 40, 90, 75, 25, 65] ITERATION Generation: #1 Best cost: 5719.493 | Path: [1, 0, 22, 4, 8, 12, 2, 3, 1, 7, 13, 20, 19, 5, 1, 9, 21, 23, 1] Best cost: 5400.193 | Path: [1, 2, 5, 12, 22, 4, 0, 1, 7, 13, 20, 3, 19, 9, 1, 8, 23, 21, 1] Best cost: 5129.822 | Path: [1, 7, 20, 13, 9, 3, 19, 1, 8, 4, 22, 12, 2, 5, 1, 0, 21, 23, 1] Best cost: 5103.537 | Path: [1, 20, 3, 19, 21, 2, 22, 1, 7, 13, 9, 23, 0, 8, 1, 4, 12, 5, 1] Best cost: 5020.514 | Path: [1, 4, 8, 22, 12, 2, 5, 19, 1, 7, 13, 20, 3, 0, 1, 9, 23, 21, 1] Best cost: 4969.914 | Path: [1, 7, 20, 13, 9, 19, 3, 1, 12, 2, 5, 21, 23, 1, 4, 22, 0, 8, 1] Best cost: 4929.342 | Path: [1, 8, 4, 22, 12, 2, 5, 19, 1, 7, 13, 20, 3, 0, 1, 9, 23, 21, 1] Generation: #3 Best cost: 4900.801 | Path: [1, 12, 2, 5, 21, 19, 3, 1, 7, 20, 13, 9, 23, 1, 4, 22, 0, 8, 1] Best cost: 4900.550 | Path: [1, 23, 21, 19, 3, 2, 5, 1, 7, 13, 9, 20, 0, 1, 4, 22, 12, 8, 1] Best cost: 4896.674 | Path: [1, 3, 19, 21, 5, 2, 12, 1, 7, 13, 20, 9, 23, 1, 8, 4, 22, 0, 1] Generation: #8 Best cost: 4871.648 | Path: [1, 7, 13, 20, 3, 19, 2, 1, 9, 23, 21, 5, 12, 1, 4, 22, 0, 8, 1] OPTIMIZING each tour... Current: [[1, 7, 13, 20, 3, 19, 2, 1], [1, 9, 23, 21, 5, 12, 1], [1, 4, 22, 0, 8, 1]] [1] Cost: 1559.831 to 1551.906 | Optimized: [1, 2, 19, 3, 20, 13, 7, 1] [3] Cost: 1206.353 to 1138.965 | Optimized: [1, 0, 22, 4, 8, 1] ACO RESULTS [1/290 vol./1551.906 km] Berlin Hbf -> Düsseldorf Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [2/295 vol./2105.464 km] Berlin Hbf -> München Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Dortmund Hbf --> Berlin Hbf [3/165 vol./1138.965 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4796.335 km.