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: 17 customers
- Berlin Hbf (100 vol.)
- Düsseldorf Hbf (95 vol.)
- Hannover Hbf (50 vol.)
- Stuttgart Hbf (75 vol.)
- Hamburg Hbf (50 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (25 vol.)
- Leipzig Hbf (85 vol.)
- Dortmund Hbf (80 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (60 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (50 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (95 vol.)
- Saarbrücken Hbf (30 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1127.176 km
LOAD: 390 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 75 vol.
- Karlsruhe Hbf | 60 vol.
Tour 2
COST: 1531.235 km
LOAD: 400 vol.
- Hannover Hbf | 50 vol.
- Dortmund Hbf | 80 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 50 vol.
- Mannheim Hbf | 75 vol.
- Freiburg Hbf | 20 vol.
- Saarbrücken Hbf | 30 vol.
Tour 3
COST: 1320.295 km
LOAD: 355 vol.
- Bremen Hbf | 25 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 95 vol.
- Berlin Hbf | 100 vol.
- Leipzig Hbf | 85 vol.
LOAD: 390 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 75 vol.
- Karlsruhe Hbf | 60 vol.
LOAD: 400 vol.
- Hannover Hbf | 50 vol.
- Dortmund Hbf | 80 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 50 vol.
- Mannheim Hbf | 75 vol.
- Freiburg Hbf | 20 vol.
- Saarbrücken Hbf | 30 vol.
LOAD: 355 vol.
- Bremen Hbf | 25 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 95 vol.
- Berlin Hbf | 100 vol.
- Leipzig 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1145 vol. | Vehicle capacity: 400 vol. Loads: [0, 100, 95, 0, 50, 0, 75, 0, 50, 95, 25, 85, 80, 65, 60, 95, 50, 75, 95, 0, 0, 30, 0, 20] ITERATION Generation: #1 Best cost: 5046.920 | Path: [0, 1, 11, 4, 10, 8, 12, 0, 16, 2, 21, 14, 17, 6, 0, 13, 9, 15, 23, 18, 0] Best cost: 4588.629 | Path: [0, 4, 10, 8, 18, 1, 13, 0, 12, 2, 16, 17, 14, 21, 0, 11, 6, 15, 9, 23, 0] Best cost: 4487.826 | Path: [0, 10, 4, 8, 18, 12, 2, 0, 17, 14, 6, 15, 9, 0, 16, 21, 23, 13, 11, 1, 0] Best cost: 4384.115 | Path: [0, 13, 9, 15, 6, 14, 0, 12, 2, 16, 21, 17, 23, 8, 0, 4, 10, 18, 1, 11, 0] Best cost: 4254.810 | Path: [0, 17, 14, 6, 15, 9, 0, 12, 2, 16, 21, 23, 13, 4, 0, 11, 1, 8, 18, 10, 0] Best cost: 4115.414 | Path: [0, 14, 6, 15, 9, 13, 0, 12, 2, 16, 21, 17, 23, 4, 0, 10, 8, 18, 1, 11, 0] Best cost: 4110.948 | Path: [0, 13, 9, 15, 6, 14, 0, 12, 2, 16, 21, 17, 23, 4, 0, 11, 1, 18, 8, 10, 0] Generation: #2 Best cost: 4109.148 | Path: [0, 13, 9, 15, 6, 14, 0, 12, 2, 16, 17, 21, 23, 4, 0, 11, 1, 18, 8, 10, 0] Best cost: 4099.877 | Path: [0, 13, 9, 15, 6, 14, 0, 12, 2, 16, 17, 21, 23, 4, 0, 10, 8, 18, 1, 11, 0] Generation: #4 Best cost: 4014.893 | Path: [0, 14, 6, 15, 9, 13, 0, 12, 2, 16, 21, 23, 17, 4, 0, 11, 1, 18, 8, 10, 0] OPTIMIZING each tour... Current: [[0, 14, 6, 15, 9, 13, 0], [0, 12, 2, 16, 21, 23, 17, 4, 0], [0, 11, 1, 18, 8, 10, 0]] [1] Cost: 1140.913 to 1127.176 | Optimized: [0, 13, 9, 15, 6, 14, 0] [2] Cost: 1544.414 to 1531.235 | Optimized: [0, 4, 12, 2, 16, 17, 23, 21, 0] [3] Cost: 1329.566 to 1320.295 | Optimized: [0, 10, 8, 18, 1, 11, 0] ACO RESULTS [1/390 vol./1127.176 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1531.235 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Mannheim Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Kassel-Wilhelmshöhe [3/355 vol./1320.295 km] Kassel-Wilhelmshöhe -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3978.706 km.