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
- Düsseldorf Hbf (75 vol.)
- Frankfurt Hbf (75 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (25 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (70 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (90 vol.)
- Dortmund Hbf (50 vol.)
- Ulm Hbf (45 vol.)
- Mannheim Hbf (50 vol.)
- Kiel Hbf (40 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (65 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1597.739 km
LOAD: 385 vol.
- Frankfurt Hbf | 75 vol.
- Mainz Hbf | 35 vol.
- Mannheim Hbf | 50 vol.
- Saarbrücken Hbf | 65 vol.
- Freiburg Hbf | 25 vol.
- Ulm Hbf | 45 vol.
- München Hbf | 60 vol.
- Würzburg Hbf | 30 vol.
Tour 2
COST: 1452.152 km
LOAD: 385 vol.
- Hannover Hbf | 85 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 70 vol.
- Kiel Hbf | 40 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 90 vol.
Tour 3
COST: 750.253 km
LOAD: 170 vol.
- Aachen Hbf | 25 vol.
- Düsseldorf Hbf | 75 vol.
- Dortmund Hbf | 50 vol.
- Osnabrück Hbf | 20 vol.
LOAD: 385 vol.
- Frankfurt Hbf | 75 vol.
- Mainz Hbf | 35 vol.
- Mannheim Hbf | 50 vol.
- Saarbrücken Hbf | 65 vol.
- Freiburg Hbf | 25 vol.
- Ulm Hbf | 45 vol.
- München Hbf | 60 vol.
- Würzburg Hbf | 30 vol.
LOAD: 385 vol.
- Hannover Hbf | 85 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 70 vol.
- Kiel Hbf | 40 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 90 vol.
LOAD: 170 vol.
- Aachen Hbf | 25 vol.
- Düsseldorf Hbf | 75 vol.
- Dortmund Hbf | 50 vol.
- Osnabrück Hbf | 20 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: 940 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 75, 75, 85, 25, 0, 25, 70, 60, 75, 90, 50, 0, 0, 45, 0, 50, 40, 35, 30, 65, 20, 25] ITERATION Generation: #1 Best cost: 5054.365 | Path: [0, 2, 12, 22, 10, 4, 8, 7, 0, 20, 3, 19, 17, 21, 23, 15, 9, 0, 11, 18, 5, 0] Best cost: 4967.970 | Path: [0, 3, 19, 17, 20, 15, 9, 23, 21, 0, 4, 10, 8, 18, 22, 12, 5, 7, 0, 2, 11, 0] Best cost: 4861.508 | Path: [0, 4, 10, 22, 12, 2, 5, 21, 0, 20, 3, 19, 17, 23, 15, 9, 7, 18, 0, 8, 11, 0] Best cost: 4289.545 | Path: [0, 7, 11, 4, 10, 8, 18, 0, 22, 12, 2, 5, 3, 19, 17, 21, 0, 20, 15, 9, 23, 0] Best cost: 4255.574 | Path: [0, 12, 2, 5, 21, 17, 19, 3, 23, 0, 22, 10, 8, 18, 4, 11, 0, 20, 15, 9, 7, 0] Best cost: 4248.208 | Path: [0, 5, 2, 12, 22, 10, 4, 8, 0, 3, 19, 17, 21, 23, 15, 9, 20, 0, 11, 7, 18, 0] Best cost: 4245.841 | Path: [0, 8, 18, 10, 22, 12, 2, 5, 19, 0, 20, 3, 17, 21, 23, 15, 9, 7, 0, 4, 11, 0] Best cost: 4166.381 | Path: [0, 19, 3, 17, 21, 23, 15, 9, 20, 0, 12, 2, 5, 22, 10, 8, 18, 7, 0, 4, 11, 0] Best cost: 4151.530 | Path: [0, 2, 5, 12, 22, 10, 8, 18, 7, 0, 3, 19, 17, 21, 23, 15, 9, 20, 0, 4, 11, 0] Best cost: 4047.859 | Path: [0, 3, 19, 17, 21, 5, 2, 12, 22, 0, 4, 10, 8, 18, 7, 11, 0, 20, 15, 9, 23, 0] Best cost: 4020.505 | Path: [0, 19, 3, 17, 23, 21, 5, 2, 12, 0, 22, 10, 8, 18, 4, 11, 0, 20, 15, 9, 7, 0] Generation: #2 Best cost: 3858.229 | Path: [0, 3, 19, 17, 21, 23, 15, 9, 20, 0, 4, 10, 8, 18, 11, 7, 0, 22, 12, 2, 5, 0] OPTIMIZING each tour... Current: [[0, 3, 19, 17, 21, 23, 15, 9, 20, 0], [0, 4, 10, 8, 18, 11, 7, 0], [0, 22, 12, 2, 5, 0]] [2] Cost: 1505.870 to 1452.152 | Optimized: [0, 4, 10, 8, 18, 7, 11, 0] [3] Cost: 754.620 to 750.253 | Optimized: [0, 5, 2, 12, 22, 0] ACO RESULTS [1/385 vol./1597.739 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Ulm Hbf -> München Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [2/385 vol./1452.152 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/170 vol./ 750.253 km] Kassel-Wilhelmshöhe -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3800.144 km.