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: 400 vol.
ACTIVE: 18 customers
- Berlin Hbf (20 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (50 vol.)
- Dresden Hbf (100 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (85 vol.)
- Bremen Hbf (60 vol.)
- Leipzig Hbf (25 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (100 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (45 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (25 vol.)
- Saarbrücken Hbf (85 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1054.241 km
LOAD: 395 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 25 vol.
- Mannheim Hbf | 45 vol.
- Saarbrücken Hbf | 85 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 65 vol.
- Dortmund Hbf | 85 vol.
Tour 2
COST: 2016.258 km
LOAD: 375 vol.
- Leipzig Hbf | 25 vol.
- Berlin Hbf | 20 vol.
- Dresden Hbf | 100 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 85 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 20 vol.
Tour 3
COST: 930.654 km
LOAD: 205 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 65 vol.
- Bremen Hbf | 60 vol.
- Hannover Hbf | 40 vol.
LOAD: 395 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 25 vol.
- Mannheim Hbf | 45 vol.
- Saarbrücken Hbf | 85 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 65 vol.
- Dortmund Hbf | 85 vol.
LOAD: 375 vol.
- Leipzig Hbf | 25 vol.
- Berlin Hbf | 20 vol.
- Dresden Hbf | 100 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 85 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 20 vol.
LOAD: 205 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 65 vol.
- Bremen Hbf | 60 vol.
- Hannover Hbf | 40 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 975 vol. | Vehicle capacity: 400 vol. Loads: [0, 20, 0, 40, 40, 50, 0, 100, 40, 85, 60, 25, 85, 25, 100, 0, 65, 45, 65, 25, 0, 85, 0, 20] ITERATION Generation: #1 Best cost: 5050.931 | Path: [0, 1, 11, 7, 4, 10, 8, 18, 19, 13, 0, 12, 16, 5, 21, 14, 0, 3, 17, 23, 9, 0] Best cost: 4630.440 | Path: [0, 4, 10, 8, 18, 1, 11, 7, 13, 19, 0, 12, 16, 5, 21, 17, 3, 23, 0, 14, 9, 0] Best cost: 4528.183 | Path: [0, 10, 4, 8, 18, 1, 7, 11, 3, 0, 12, 16, 5, 17, 14, 23, 19, 0, 13, 9, 21, 0] Best cost: 4474.706 | Path: [0, 13, 9, 14, 17, 19, 3, 16, 0, 12, 5, 21, 23, 11, 7, 1, 0, 4, 10, 8, 18, 0] Best cost: 4436.512 | Path: [0, 9, 13, 17, 14, 23, 21, 19, 0, 12, 16, 5, 3, 1, 11, 7, 0, 4, 10, 8, 18, 0] Best cost: 4433.736 | Path: [0, 5, 16, 12, 10, 8, 18, 1, 0, 4, 11, 7, 13, 9, 14, 23, 0, 3, 19, 17, 21, 0] Best cost: 4326.446 | Path: [0, 12, 16, 5, 17, 14, 23, 19, 0, 3, 21, 13, 9, 11, 7, 1, 0, 4, 10, 8, 18, 0] Best cost: 4222.562 | Path: [0, 1, 11, 7, 13, 9, 14, 17, 0, 12, 16, 5, 19, 3, 21, 23, 0, 4, 10, 8, 18, 0] Best cost: 4196.340 | Path: [0, 1, 7, 11, 13, 9, 14, 17, 0, 12, 16, 5, 19, 3, 21, 23, 0, 4, 10, 8, 18, 0] Best cost: 4119.523 | Path: [0, 11, 7, 1, 8, 18, 10, 4, 3, 0, 19, 17, 14, 21, 23, 9, 13, 0, 12, 16, 5, 0] Best cost: 4088.037 | Path: [0, 13, 9, 17, 14, 23, 21, 19, 0, 4, 10, 8, 18, 1, 11, 7, 3, 0, 12, 16, 5, 0] Generation: #8 Best cost: 4041.776 | Path: [0, 12, 16, 5, 21, 17, 19, 3, 0, 14, 23, 9, 13, 11, 7, 1, 0, 4, 10, 8, 18, 0] OPTIMIZING each tour... Current: [[0, 12, 16, 5, 21, 17, 19, 3, 0], [0, 14, 23, 9, 13, 11, 7, 1, 0], [0, 4, 10, 8, 18, 0]] [1] Cost: 1054.812 to 1054.241 | Optimized: [0, 3, 19, 17, 21, 5, 16, 12, 0] [2] Cost: 2042.359 to 2016.258 | Optimized: [0, 11, 1, 7, 13, 9, 14, 23, 0] [3] Cost: 944.605 to 930.654 | Optimized: [0, 8, 18, 10, 4, 0] ACO RESULTS [1/395 vol./1054.241 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [2/375 vol./2016.258 km] Kassel-Wilhelmshöhe -> Leipzig Hbf -> Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [3/205 vol./ 930.654 km] Kassel-Wilhelmshöhe -> Hamburg Hbf -> Kiel Hbf -> Bremen Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4001.153 km.