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 (80 vol.)
- Düsseldorf Hbf (50 vol.)
- Hannover Hbf (35 vol.)
- Stuttgart Hbf (100 vol.)
- Hamburg Hbf (90 vol.)
- Bremen Hbf (60 vol.)
- Leipzig Hbf (50 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (70 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (45 vol.)
- Mainz Hbf (50 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (65 vol.)
- Osnabrück Hbf (65 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1327.422 km
LOAD: 360 vol.
- Hannover Hbf | 35 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 45 vol.
- Berlin Hbf | 80 vol.
- Leipzig Hbf | 50 vol.
Tour 2
COST: 926.311 km
LOAD: 355 vol.
- Mannheim Hbf | 70 vol.
- Karlsruhe Hbf | 65 vol.
- Stuttgart Hbf | 100 vol.
- Ulm Hbf | 70 vol.
- Würzburg Hbf | 50 vol.
Tour 3
COST: 1387.824 km
LOAD: 380 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 65 vol.
- Mainz Hbf | 50 vol.
- Köln Hbf | 70 vol.
- Düsseldorf Hbf | 50 vol.
- Osnabrück Hbf | 65 vol.
LOAD: 360 vol.
- Hannover Hbf | 35 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 45 vol.
- Berlin Hbf | 80 vol.
- Leipzig Hbf | 50 vol.
LOAD: 355 vol.
- Mannheim Hbf | 70 vol.
- Karlsruhe Hbf | 65 vol.
- Stuttgart Hbf | 100 vol.
- Ulm Hbf | 70 vol.
- Würzburg Hbf | 50 vol.
LOAD: 380 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 65 vol.
- Mainz Hbf | 50 vol.
- Köln Hbf | 70 vol.
- Düsseldorf Hbf | 50 vol.
- Osnabrück Hbf | 65 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: 1095 vol. | Vehicle capacity: 400 vol. Loads: [0, 80, 50, 0, 35, 0, 100, 0, 90, 0, 60, 50, 0, 0, 65, 70, 70, 70, 45, 50, 50, 65, 65, 80] ITERATION Generation: #1 Best cost: 4811.434 | Path: [0, 1, 11, 4, 22, 10, 8, 0, 19, 17, 14, 6, 15, 18, 0, 20, 16, 2, 21, 23, 0] Best cost: 4280.497 | Path: [0, 2, 16, 19, 17, 14, 23, 0, 4, 10, 22, 8, 18, 1, 0, 20, 6, 15, 21, 11, 0] Best cost: 4278.132 | Path: [0, 15, 6, 14, 17, 19, 4, 0, 22, 10, 8, 18, 11, 1, 0, 20, 21, 23, 16, 2, 0] Best cost: 3837.024 | Path: [0, 17, 14, 6, 15, 20, 4, 0, 22, 10, 8, 18, 1, 11, 0, 2, 16, 19, 21, 23, 0] Best cost: 3774.836 | Path: [0, 11, 1, 18, 8, 10, 4, 0, 22, 16, 2, 19, 17, 14, 0, 20, 6, 15, 23, 21, 0] Best cost: 3766.377 | Path: [0, 4, 10, 8, 18, 1, 11, 0, 22, 16, 2, 19, 17, 14, 0, 20, 6, 15, 23, 21, 0] Best cost: 3762.355 | Path: [0, 14, 17, 19, 2, 16, 22, 0, 4, 10, 8, 18, 1, 11, 0, 20, 6, 15, 23, 21, 0] Best cost: 3725.547 | Path: [0, 11, 1, 8, 18, 10, 4, 0, 22, 2, 16, 19, 17, 14, 0, 20, 6, 15, 23, 21, 0] Best cost: 3701.747 | Path: [0, 14, 17, 19, 16, 2, 22, 0, 4, 10, 8, 18, 1, 11, 0, 20, 6, 15, 23, 21, 0] Generation: #4 Best cost: 3676.423 | Path: [0, 4, 10, 8, 18, 1, 11, 0, 20, 6, 15, 14, 17, 0, 22, 2, 16, 19, 21, 23, 0] OPTIMIZING each tour... Current: [[0, 4, 10, 8, 18, 1, 11, 0], [0, 20, 6, 15, 14, 17, 0], [0, 22, 2, 16, 19, 21, 23, 0]] [2] Cost: 954.822 to 926.311 | Optimized: [0, 17, 14, 6, 15, 20, 0] [3] Cost: 1394.179 to 1387.824 | Optimized: [0, 23, 21, 19, 16, 2, 22, 0] ACO RESULTS [1/360 vol./1327.422 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/355 vol./ 926.311 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [3/380 vol./1387.824 km] Kassel-Wilhelmshöhe -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Köln Hbf -> Düsseldorf Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3641.557 km.