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 (65 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (75 vol.)
- Aachen Hbf (25 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (30 vol.)
- Hamburg Hbf (70 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (85 vol.)
- Nürnberg Hbf (70 vol.)
- Karlsruhe Hbf (25 vol.)
- Ulm Hbf (70 vol.)
- Köln Hbf (100 vol.)
- Mannheim Hbf (20 vol.)
- Mainz Hbf (60 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (40 vol.)
Tour 1
COST: 1056.84 km
LOAD: 390 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 60 vol.
- Mannheim Hbf | 20 vol.
- Saarbrücken Hbf | 80 vol.
- Aachen Hbf | 25 vol.
- Köln Hbf | 100 vol.
- Düsseldorf Hbf | 65 vol.
Tour 2
COST: 1318.176 km
LOAD: 395 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 70 vol.
- Hannover Hbf | 75 vol.
- Leipzig Hbf | 85 vol.
- Dresden Hbf | 30 vol.
Tour 3
COST: 1278.691 km
LOAD: 235 vol.
- Nürnberg Hbf | 70 vol.
- Ulm Hbf | 70 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 25 vol.
- Freiburg Hbf | 40 vol.
LOAD: 390 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 60 vol.
- Mannheim Hbf | 20 vol.
- Saarbrücken Hbf | 80 vol.
- Aachen Hbf | 25 vol.
- Köln Hbf | 100 vol.
- Düsseldorf Hbf | 65 vol.
LOAD: 395 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 70 vol.
- Hannover Hbf | 75 vol.
- Leipzig Hbf | 85 vol.
- Dresden Hbf | 30 vol.
LOAD: 235 vol.
- Nürnberg Hbf | 70 vol.
- Ulm Hbf | 70 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 25 vol.
- Freiburg 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: 1020 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 65, 40, 75, 25, 30, 30, 70, 0, 45, 85, 0, 70, 25, 70, 100, 20, 0, 60, 0, 80, 90, 40] ITERATION Generation: #1 Best cost: 4550.264 | Path: [0, 2, 16, 5, 4, 10, 22, 0, 19, 3, 17, 14, 6, 15, 13, 11, 0, 8, 7, 23, 21, 0] Best cost: 4433.729 | Path: [0, 3, 19, 17, 14, 6, 15, 13, 11, 0, 22, 10, 8, 4, 2, 5, 7, 0, 16, 21, 23, 0] Best cost: 4297.840 | Path: [0, 5, 16, 2, 22, 10, 8, 0, 4, 19, 3, 17, 14, 6, 15, 13, 0, 11, 7, 21, 23, 0] Best cost: 4096.613 | Path: [0, 8, 10, 22, 4, 11, 7, 0, 2, 16, 5, 17, 14, 6, 15, 3, 0, 19, 21, 23, 13, 0] Best cost: 4068.054 | Path: [0, 21, 17, 14, 6, 15, 13, 19, 3, 0, 22, 10, 8, 4, 11, 7, 0, 16, 2, 5, 23, 0] Best cost: 3874.154 | Path: [0, 2, 16, 5, 21, 19, 3, 17, 0, 4, 22, 10, 8, 11, 7, 0, 13, 15, 6, 14, 23, 0] Generation: #2 Best cost: 3872.255 | Path: [0, 5, 16, 2, 22, 10, 8, 0, 4, 11, 7, 13, 15, 6, 14, 0, 3, 19, 17, 21, 23, 0] Best cost: 3802.422 | Path: [0, 11, 7, 13, 15, 6, 14, 17, 19, 0, 22, 10, 8, 4, 16, 0, 2, 5, 21, 23, 3, 0] Generation: #3 Best cost: 3742.302 | Path: [0, 2, 16, 5, 21, 19, 3, 17, 0, 22, 10, 8, 4, 11, 7, 0, 13, 15, 6, 14, 23, 0] OPTIMIZING each tour... Current: [[0, 2, 16, 5, 21, 19, 3, 17, 0], [0, 22, 10, 8, 4, 11, 7, 0], [0, 13, 15, 6, 14, 23, 0]] [1] Cost: 1145.435 to 1056.840 | Optimized: [0, 3, 19, 17, 21, 5, 16, 2, 0] ACO RESULTS [1/390 vol./1056.840 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe [2/395 vol./1318.176 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Hannover Hbf -> Leipzig Hbf -> Dresden Hbf --> Kassel-Wilhelmshöhe [3/235 vol./1278.691 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3653.707 km.