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: 21 customers
- Berlin Hbf (100 vol.)
- Düsseldorf Hbf (60 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (55 vol.)
- Stuttgart Hbf (100 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (50 vol.)
- Leipzig Hbf (25 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (75 vol.)
- Köln Hbf (45 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (40 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1453.615 km
LOAD: 385 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 50 vol.
- Hamburg Hbf | 65 vol.
- Kiel Hbf | 50 vol.
- Berlin Hbf | 100 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 25 vol.
Tour 2
COST: 1116.621 km
LOAD: 400 vol.
- Frankfurt Hbf | 55 vol.
- Mainz Hbf | 95 vol.
- Saarbrücken Hbf | 50 vol.
- Aachen Hbf | 55 vol.
- Köln Hbf | 45 vol.
- Düsseldorf Hbf | 60 vol.
- Osnabrück Hbf | 40 vol.
Tour 3
COST: 1120.194 km
LOAD: 320 vol.
- Würzburg Hbf | 60 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 25 vol.
- Stuttgart Hbf | 100 vol.
- Karlsruhe Hbf | 75 vol.
Tour 4
COST: 931.689 km
LOAD: 190 vol.
- Mannheim Hbf | 100 vol.
- Freiburg Hbf | 90 vol.
LOAD: 385 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 50 vol.
- Hamburg Hbf | 65 vol.
- Kiel Hbf | 50 vol.
- Berlin Hbf | 100 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 25 vol.
LOAD: 400 vol.
- Frankfurt Hbf | 55 vol.
- Mainz Hbf | 95 vol.
- Saarbrücken Hbf | 50 vol.
- Aachen Hbf | 55 vol.
- Köln Hbf | 45 vol.
- Düsseldorf Hbf | 60 vol.
- Osnabrück Hbf | 40 vol.
LOAD: 320 vol.
- Würzburg Hbf | 60 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 25 vol.
- Stuttgart Hbf | 100 vol.
- Karlsruhe Hbf | 75 vol.
LOAD: 190 vol.
- Mannheim Hbf | 100 vol.
- Freiburg Hbf | 90 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: 1295 vol. | Vehicle capacity: 400 vol. Loads: [0, 100, 60, 55, 50, 55, 100, 45, 65, 25, 50, 25, 0, 60, 75, 0, 45, 100, 50, 95, 60, 50, 40, 90] ITERATION Generation: #1 Best cost: 5567.503 | Path: [0, 1, 11, 7, 13, 20, 3, 21, 0, 19, 17, 14, 6, 9, 0, 22, 4, 8, 18, 10, 16, 2, 0, 5, 23, 0] Best cost: 5330.014 | Path: [0, 2, 16, 5, 21, 14, 6, 0, 22, 10, 4, 8, 18, 1, 11, 0, 20, 13, 9, 17, 19, 3, 0, 7, 23, 0] Best cost: 5305.901 | Path: [0, 11, 7, 1, 8, 18, 10, 4, 0, 22, 2, 16, 5, 14, 17, 9, 0, 19, 3, 20, 13, 6, 0, 21, 23, 0] Best cost: 5150.416 | Path: [0, 2, 16, 5, 17, 14, 20, 0, 3, 19, 21, 23, 6, 0, 4, 10, 22, 8, 18, 1, 11, 0, 13, 9, 7, 0] Best cost: 5132.658 | Path: [0, 7, 11, 1, 8, 18, 10, 4, 0, 20, 3, 19, 17, 14, 0, 22, 2, 16, 5, 21, 23, 13, 0, 6, 9, 0] Best cost: 5101.715 | Path: [0, 11, 7, 1, 8, 18, 10, 4, 0, 22, 2, 16, 5, 17, 14, 9, 0, 20, 13, 6, 19, 3, 0, 21, 23, 0] Best cost: 5061.801 | Path: [0, 17, 14, 6, 20, 3, 0, 4, 10, 22, 2, 16, 5, 19, 0, 11, 1, 7, 13, 9, 23, 21, 0, 8, 18, 0] Best cost: 5050.250 | Path: [0, 14, 17, 3, 19, 20, 0, 2, 16, 5, 21, 23, 6, 0, 22, 4, 10, 8, 18, 1, 11, 0, 13, 9, 7, 0] Best cost: 4912.408 | Path: [0, 11, 7, 1, 4, 8, 18, 10, 0, 22, 2, 16, 5, 21, 14, 3, 0, 20, 13, 9, 6, 17, 0, 19, 23, 0] Best cost: 4843.934 | Path: [0, 11, 7, 1, 8, 18, 10, 4, 0, 22, 16, 2, 5, 17, 19, 0, 3, 20, 13, 9, 6, 14, 0, 21, 23, 0] Best cost: 4840.139 | Path: [0, 11, 7, 1, 8, 18, 10, 4, 0, 22, 2, 16, 5, 19, 3, 21, 0, 20, 13, 9, 6, 14, 0, 17, 23, 0] Best cost: 4770.911 | Path: [0, 10, 4, 8, 18, 1, 7, 11, 0, 20, 13, 9, 6, 14, 3, 0, 22, 2, 16, 5, 21, 19, 0, 17, 23, 0] Generation: #2 Best cost: 4673.267 | Path: [0, 11, 7, 1, 8, 18, 10, 4, 0, 20, 13, 9, 6, 14, 21, 0, 22, 2, 16, 5, 19, 3, 0, 17, 23, 0] Generation: #3 Best cost: 4651.037 | Path: [0, 11, 7, 1, 8, 18, 10, 4, 0, 22, 2, 16, 5, 21, 19, 3, 0, 20, 13, 9, 6, 14, 0, 17, 23, 0] Generation: #7 Best cost: 4633.891 | Path: [0, 4, 10, 8, 18, 1, 7, 11, 0, 22, 2, 16, 5, 21, 14, 3, 0, 20, 13, 9, 6, 23, 0, 17, 19, 0] Generation: #9 Best cost: 4630.420 | Path: [0, 4, 10, 8, 18, 1, 7, 11, 0, 22, 2, 16, 5, 21, 19, 3, 0, 20, 13, 9, 6, 14, 0, 17, 23, 0] OPTIMIZING each tour... Current: [[0, 4, 10, 8, 18, 1, 7, 11, 0], [0, 22, 2, 16, 5, 21, 19, 3, 0], [0, 20, 13, 9, 6, 14, 0], [0, 17, 23, 0]] [2] Cost: 1124.922 to 1116.621 | Optimized: [0, 3, 19, 21, 5, 16, 2, 22, 0] ACO RESULTS [1/385 vol./1453.615 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1116.621 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe [3/320 vol./1120.194 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf --> Kassel-Wilhelmshöhe [4/190 vol./ 931.689 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4622.119 km.