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: 17 customers
- Kassel-Wilhelmshöhe (20 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (35 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (25 vol.)
- Köln Hbf (50 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (55 vol.)
- Saarbrücken Hbf (55 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 1944.262 km
LOAD: 300 vol.
- München Hbf | 35 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 25 vol.
- Freiburg Hbf | 55 vol.
- Saarbrücken Hbf | 55 vol.
- Mainz Hbf | 100 vol.
Tour 2
COST: 1334.268 km
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Frankfurt Hbf | 55 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 75 vol.
- Dresden Hbf | 90 vol.
Tour 3
COST: 1443.1 km
LOAD: 275 vol.
- Hamburg Hbf | 65 vol.
- Osnabrück Hbf | 85 vol.
- Köln Hbf | 50 vol.
- Aachen Hbf | 50 vol.
- Hannover Hbf | 25 vol.
Tour 4
COST: 701.943 km
LOAD: 50 vol.
- Kiel Hbf | 50 vol.
LOAD: 300 vol.
- München Hbf | 35 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 25 vol.
- Freiburg Hbf | 55 vol.
- Saarbrücken Hbf | 55 vol.
- Mainz Hbf | 100 vol.
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Frankfurt Hbf | 55 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 75 vol.
- Dresden Hbf | 90 vol.
LOAD: 275 vol.
- Hamburg Hbf | 65 vol.
- Osnabrück Hbf | 85 vol.
- Köln Hbf | 50 vol.
- Aachen Hbf | 50 vol.
- Hannover Hbf | 25 vol.
LOAD: 50 vol.
- Kiel Hbf | 50 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: 920 vol. | Vehicle capacity: 300 vol. Loads: [20, 0, 0, 55, 25, 50, 30, 90, 65, 35, 0, 0, 0, 75, 25, 0, 50, 0, 50, 100, 55, 55, 85, 55] ITERATION Generation: #1 Best cost: 7288.596 | Path: [1, 0, 22, 4, 8, 18, 3, 1, 7, 13, 20, 6, 14, 1, 16, 5, 19, 21, 9, 1, 23, 1] Best cost: 6922.325 | Path: [1, 3, 19, 21, 14, 6, 9, 1, 7, 0, 4, 22, 16, 1, 8, 18, 5, 20, 13, 1, 23, 1] Best cost: 6491.439 | Path: [1, 4, 0, 3, 19, 21, 14, 1, 7, 13, 20, 6, 9, 1, 8, 18, 22, 16, 5, 1, 23, 1] Best cost: 5994.272 | Path: [1, 6, 14, 23, 21, 19, 0, 1, 7, 13, 20, 3, 4, 1, 8, 18, 22, 16, 5, 1, 9, 1] Best cost: 5798.040 | Path: [1, 13, 20, 3, 19, 1, 7, 9, 6, 14, 21, 23, 1, 4, 22, 0, 16, 5, 8, 1, 18, 1] Best cost: 5670.733 | Path: [1, 13, 20, 3, 19, 1, 7, 0, 22, 4, 8, 1, 9, 6, 14, 21, 23, 5, 16, 1, 18, 1] Best cost: 5487.322 | Path: [1, 9, 6, 14, 23, 21, 19, 1, 7, 13, 20, 3, 0, 1, 4, 22, 16, 5, 18, 1, 8, 1] Generation: #2 Best cost: 5475.764 | Path: [1, 9, 6, 14, 23, 21, 19, 1, 7, 13, 20, 3, 0, 1, 4, 22, 16, 5, 8, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 9, 6, 14, 23, 21, 19, 1], [1, 7, 13, 20, 3, 0, 1], [1, 4, 22, 16, 5, 8, 1], [1, 18, 1]] [2] Cost: 1341.111 to 1334.268 | Optimized: [1, 0, 3, 20, 13, 7, 1] [3] Cost: 1488.448 to 1443.100 | Optimized: [1, 8, 22, 16, 5, 4, 1] ACO RESULTS [1/300 vol./1944.262 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf --> Berlin Hbf [2/295 vol./1334.268 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/275 vol./1443.100 km] Berlin Hbf -> Hamburg Hbf -> Osnabrück Hbf -> Köln Hbf -> Aachen Hbf -> Hannover Hbf --> Berlin Hbf [4/ 50 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5423.573 km.