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: 22 customers
- Berlin Hbf (50 vol.)
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (90 vol.)
- Stuttgart Hbf (35 vol.)
- Dresden Hbf (40 vol.)
- Hamburg Hbf (55 vol.)
- München Hbf (45 vol.)
- Bremen Hbf (30 vol.)
- Leipzig Hbf (75 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (60 vol.)
- Köln Hbf (85 vol.)
- Mannheim Hbf (65 vol.)
- Kiel Hbf (30 vol.)
- Mainz Hbf (70 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 917.595 km
LOAD: 390 vol.
- Mannheim Hbf | 65 vol.
- Mainz Hbf | 70 vol.
- Köln Hbf | 85 vol.
- Aachen Hbf | 90 vol.
- Düsseldorf Hbf | 80 vol.
Tour 2
COST: 1535.861 km
LOAD: 395 vol.
- Würzburg Hbf | 25 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 60 vol.
- Stuttgart Hbf | 35 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 30 vol.
- Frankfurt Hbf | 90 vol.
Tour 3
COST: 1597.529 km
LOAD: 325 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 30 vol.
- Hannover Hbf | 25 vol.
- Hamburg Hbf | 55 vol.
- Kiel Hbf | 30 vol.
- Berlin Hbf | 50 vol.
- Dresden Hbf | 40 vol.
- Leipzig Hbf | 75 vol.
LOAD: 390 vol.
- Mannheim Hbf | 65 vol.
- Mainz Hbf | 70 vol.
- Köln Hbf | 85 vol.
- Aachen Hbf | 90 vol.
- Düsseldorf Hbf | 80 vol.
LOAD: 395 vol.
- Würzburg Hbf | 25 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 60 vol.
- Stuttgart Hbf | 35 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 30 vol.
- Frankfurt Hbf | 90 vol.
LOAD: 325 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 30 vol.
- Hannover Hbf | 25 vol.
- Hamburg Hbf | 55 vol.
- Kiel Hbf | 30 vol.
- Berlin Hbf | 50 vol.
- Dresden Hbf | 40 vol.
- Leipzig Hbf | 75 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: 1110 vol. | Vehicle capacity: 400 vol. Loads: [0, 50, 80, 90, 25, 90, 35, 40, 55, 45, 30, 75, 0, 40, 45, 60, 85, 65, 30, 70, 25, 30, 20, 25] ITERATION Generation: #1 Best cost: 5694.964 | Path: [0, 1, 11, 7, 4, 10, 22, 2, 19, 0, 16, 5, 21, 14, 6, 15, 9, 0, 3, 17, 20, 13, 23, 8, 18, 0] Best cost: 4986.211 | Path: [0, 2, 16, 5, 19, 17, 0, 22, 10, 8, 18, 1, 11, 7, 13, 20, 6, 0, 4, 3, 14, 21, 23, 15, 9, 0] Best cost: 4511.108 | Path: [0, 3, 19, 17, 14, 6, 15, 20, 0, 2, 16, 5, 21, 23, 13, 9, 0, 22, 10, 4, 8, 18, 1, 11, 7, 0] Best cost: 4458.049 | Path: [0, 19, 3, 17, 14, 6, 15, 20, 0, 16, 2, 5, 21, 23, 13, 9, 0, 22, 10, 4, 8, 18, 1, 7, 11, 0] Best cost: 4410.701 | Path: [0, 16, 2, 5, 17, 14, 23, 0, 19, 3, 21, 6, 15, 9, 13, 20, 0, 4, 10, 22, 8, 18, 1, 7, 11, 0] Best cost: 4290.349 | Path: [0, 3, 19, 17, 14, 6, 15, 20, 0, 2, 16, 5, 21, 23, 9, 13, 0, 22, 10, 4, 8, 18, 1, 7, 11, 0] Generation: #2 Best cost: 4256.524 | Path: [0, 2, 16, 5, 19, 17, 0, 3, 20, 13, 9, 15, 6, 14, 23, 21, 0, 4, 22, 10, 8, 18, 1, 11, 7, 0] Generation: #3 Best cost: 4187.463 | Path: [0, 20, 13, 9, 15, 6, 14, 17, 19, 0, 3, 23, 21, 5, 16, 2, 0, 22, 10, 8, 18, 4, 11, 7, 1, 0] Generation: #6 Best cost: 4070.047 | Path: [0, 2, 16, 5, 19, 17, 0, 20, 13, 9, 15, 6, 14, 23, 21, 3, 0, 22, 10, 4, 8, 18, 1, 7, 11, 0] OPTIMIZING each tour... Current: [[0, 2, 16, 5, 19, 17, 0], [0, 20, 13, 9, 15, 6, 14, 23, 21, 3, 0], [0, 22, 10, 4, 8, 18, 1, 7, 11, 0]] [1] Cost: 936.657 to 917.595 | Optimized: [0, 17, 19, 16, 5, 2, 0] ACO RESULTS [1/390 vol./ 917.595 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Mainz Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe [2/395 vol./1535.861 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/325 vol./1597.529 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4050.985 km.