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: 18 customers
- Kassel-Wilhelmshöhe (95 vol.)
- Düsseldorf Hbf (45 vol.)
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (30 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (30 vol.)
- Dortmund Hbf (95 vol.)
- Karlsruhe Hbf (30 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (80 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (25 vol.)
- Osnabrück Hbf (85 vol.)
Tour 1
COST: 1448.546 km
LOAD: 290 vol.
- Frankfurt Hbf | 45 vol.
- Mannheim Hbf | 90 vol.
- Würzburg Hbf | 95 vol.
- Leipzig Hbf | 30 vol.
- Dresden Hbf | 30 vol.
Tour 2
COST: 1101.702 km
LOAD: 290 vol.
- Hannover Hbf | 25 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 100 vol.
- Kiel Hbf | 80 vol.
Tour 3
COST: 1935.641 km
LOAD: 300 vol.
- München Hbf | 100 vol.
- Stuttgart Hbf | 60 vol.
- Karlsruhe Hbf | 30 vol.
- Saarbrücken Hbf | 25 vol.
- Aachen Hbf | 30 vol.
- Köln Hbf | 55 vol.
Tour 4
COST: 1175.326 km
LOAD: 235 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 95 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 45 vol.
- Mannheim Hbf | 90 vol.
- Würzburg Hbf | 95 vol.
- Leipzig Hbf | 30 vol.
- Dresden Hbf | 30 vol.
LOAD: 290 vol.
- Hannover Hbf | 25 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 100 vol.
- Kiel Hbf | 80 vol.
LOAD: 300 vol.
- München Hbf | 100 vol.
- Stuttgart Hbf | 60 vol.
- Karlsruhe Hbf | 30 vol.
- Saarbrücken Hbf | 25 vol.
- Aachen Hbf | 30 vol.
- Köln Hbf | 55 vol.
LOAD: 235 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 95 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: 1115 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 45, 45, 25, 30, 60, 30, 0, 100, 100, 30, 95, 0, 30, 0, 55, 90, 80, 0, 95, 25, 85, 0] ITERATION Generation: #1 Best cost: 6236.700 | Path: [1, 0, 4, 22, 12, 1, 11, 7, 20, 3, 17, 1, 18, 10, 16, 2, 1, 5, 21, 14, 6, 9, 1] Best cost: 6024.822 | Path: [1, 2, 16, 12, 22, 1, 7, 11, 0, 4, 10, 1, 18, 5, 21, 17, 14, 3, 1, 20, 6, 9, 1] Best cost: 5767.242 | Path: [1, 4, 22, 10, 18, 1, 11, 7, 20, 3, 17, 1, 0, 12, 2, 16, 1, 5, 21, 14, 6, 9, 1] Best cost: 5756.384 | Path: [1, 18, 10, 22, 4, 1, 7, 11, 9, 6, 14, 3, 1, 0, 12, 2, 16, 1, 20, 17, 21, 5, 1] Best cost: 5730.932 | Path: [1, 2, 16, 5, 12, 4, 11, 1, 0, 3, 17, 14, 21, 1, 7, 20, 6, 9, 1, 18, 10, 22, 1] Generation: #7 Best cost: 5719.703 | Path: [1, 11, 7, 20, 3, 17, 1, 18, 10, 22, 4, 1, 9, 6, 14, 21, 5, 16, 1, 0, 12, 2, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 20, 3, 17, 1], [1, 18, 10, 22, 4, 1], [1, 9, 6, 14, 21, 5, 16, 1], [1, 0, 12, 2, 1]] [1] Cost: 1500.893 to 1448.546 | Optimized: [1, 3, 17, 20, 11, 7, 1] [2] Cost: 1106.333 to 1101.702 | Optimized: [1, 4, 22, 10, 18, 1] [4] Cost: 1176.836 to 1175.326 | Optimized: [1, 12, 2, 0, 1] ACO RESULTS [1/290 vol./1448.546 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [2/290 vol./1101.702 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [3/300 vol./1935.641 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf --> Berlin Hbf [4/235 vol./1175.326 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5661.215 km.