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
- Kassel-Wilhelmshöhe (80 vol.)
- Frankfurt Hbf (95 vol.)
- Aachen Hbf (30 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (25 vol.)
- München Hbf (35 vol.)
- Bremen Hbf (85 vol.)
- Dortmund Hbf (45 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (80 vol.)
- Kiel Hbf (45 vol.)
- Mainz Hbf (80 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (95 vol.)
- Osnabrück Hbf (55 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1947.353 km
LOAD: 285 vol.
- München Hbf | 35 vol.
- Ulm Hbf | 80 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 95 vol.
Tour 2
COST: 1366.281 km
LOAD: 275 vol.
- Dresden Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 80 vol.
- Dortmund Hbf | 45 vol.
- Osnabrück Hbf | 55 vol.
- Hamburg Hbf | 25 vol.
Tour 3
COST: 1511.602 km
LOAD: 300 vol.
- Aachen Hbf | 30 vol.
- Mainz Hbf | 80 vol.
- Frankfurt Hbf | 95 vol.
- Würzburg Hbf | 95 vol.
Tour 4
COST: 944.451 km
LOAD: 130 vol.
- Kiel Hbf | 45 vol.
- Bremen Hbf | 85 vol.
LOAD: 285 vol.
- München Hbf | 35 vol.
- Ulm Hbf | 80 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 95 vol.
LOAD: 275 vol.
- Dresden Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 80 vol.
- Dortmund Hbf | 45 vol.
- Osnabrück Hbf | 55 vol.
- Hamburg Hbf | 25 vol.
LOAD: 300 vol.
- Aachen Hbf | 30 vol.
- Mainz Hbf | 80 vol.
- Frankfurt Hbf | 95 vol.
- Würzburg Hbf | 95 vol.
LOAD: 130 vol.
- Kiel Hbf | 45 vol.
- Bremen 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: 990 vol. | Vehicle capacity: 300 vol. Loads: [80, 0, 0, 95, 0, 30, 0, 70, 25, 35, 85, 0, 45, 0, 40, 80, 0, 0, 45, 80, 95, 95, 55, 35] ITERATION Generation: #1 Best cost: 6466.059 | Path: [1, 0, 12, 22, 10, 8, 1, 7, 20, 3, 14, 1, 18, 5, 21, 19, 23, 1, 15, 9, 1] Best cost: 6224.397 | Path: [1, 5, 12, 22, 10, 8, 18, 1, 7, 20, 3, 14, 1, 0, 19, 21, 23, 1, 9, 15, 1] Best cost: 6218.033 | Path: [1, 5, 12, 22, 10, 8, 18, 1, 7, 14, 23, 21, 9, 1, 0, 3, 19, 1, 20, 15, 1] Best cost: 6151.817 | Path: [1, 9, 15, 14, 23, 21, 1, 7, 20, 3, 5, 1, 8, 10, 22, 12, 19, 1, 18, 0, 1] Best cost: 6125.050 | Path: [1, 9, 15, 14, 23, 21, 1, 7, 0, 22, 10, 1, 8, 18, 12, 5, 19, 1, 20, 3, 1] Best cost: 6076.706 | Path: [1, 21, 19, 3, 5, 1, 7, 0, 22, 12, 8, 1, 20, 14, 23, 15, 9, 1, 18, 10, 1] Best cost: 6051.059 | Path: [1, 9, 15, 14, 23, 21, 1, 7, 20, 3, 5, 1, 8, 18, 10, 22, 12, 1, 0, 19, 1] Generation: #2 Best cost: 5771.979 | Path: [1, 9, 15, 14, 23, 21, 1, 7, 0, 12, 22, 8, 1, 20, 3, 19, 5, 1, 18, 10, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 14, 23, 21, 1], [1, 7, 0, 12, 22, 8, 1], [1, 20, 3, 19, 5, 1], [1, 18, 10, 1]] [3] Cost: 1513.894 to 1511.602 | Optimized: [1, 5, 19, 3, 20, 1] ACO RESULTS [1/285 vol./1947.353 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [2/275 vol./1366.281 km] Berlin Hbf -> Dresden Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Osnabrück Hbf -> Hamburg Hbf --> Berlin Hbf [3/300 vol./1511.602 km] Berlin Hbf -> Aachen Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf --> Berlin Hbf [4/130 vol./ 944.451 km] Berlin Hbf -> Kiel Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5769.687 km.