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: 300 vol.
ACTIVE: 18 customers
- Kassel-Wilhelmshöhe (35 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (80 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (90 vol.)
- Hamburg Hbf (75 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (30 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (90 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (25 vol.)
- Würzburg Hbf (35 vol.)
- Osnabrück Hbf (95 vol.)
- Freiburg Hbf (100 vol.)
Tour 1
COST: 1312.887 km
LOAD: 295 vol.
- Dortmund Hbf | 30 vol.
- Düsseldorf Hbf | 90 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 60 vol.
- Hannover Hbf | 80 vol.
Tour 2
COST: 1431.127 km
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Frankfurt Hbf | 30 vol.
- Mannheim Hbf | 20 vol.
- Würzburg Hbf | 35 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 80 vol.
Tour 3
COST: 1107.833 km
LOAD: 240 vol.
- Osnabrück Hbf | 95 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 25 vol.
Tour 4
COST: 1645.527 km
LOAD: 280 vol.
- Stuttgart Hbf | 90 vol.
- Karlsruhe Hbf | 90 vol.
- Freiburg Hbf | 100 vol.
LOAD: 295 vol.
- Dortmund Hbf | 30 vol.
- Düsseldorf Hbf | 90 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 60 vol.
- Hannover Hbf | 80 vol.
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Frankfurt Hbf | 30 vol.
- Mannheim Hbf | 20 vol.
- Würzburg Hbf | 35 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 80 vol.
LOAD: 240 vol.
- Osnabrück Hbf | 95 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 25 vol.
LOAD: 280 vol.
- Stuttgart Hbf | 90 vol.
- Karlsruhe Hbf | 90 vol.
- Freiburg Hbf | 100 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: [1] Berlin Hbf | Number of cities: 24 | Total loads: 1095 vol. | Vehicle capacity: 300 vol. Loads: [35, 0, 90, 30, 80, 60, 90, 0, 75, 0, 45, 80, 30, 80, 90, 0, 35, 20, 25, 0, 35, 0, 95, 100] ITERATION Generation: #1 Best cost: 6290.354 | Path: [1, 0, 12, 2, 16, 5, 3, 17, 1, 11, 4, 10, 8, 1, 18, 22, 6, 14, 1, 13, 20, 23, 1] Best cost: 6035.905 | Path: [1, 3, 17, 14, 6, 20, 0, 1, 11, 4, 22, 10, 1, 8, 18, 2, 16, 5, 1, 13, 23, 12, 1] Best cost: 5846.594 | Path: [1, 12, 2, 16, 5, 3, 17, 0, 1, 11, 13, 20, 6, 1, 18, 8, 10, 4, 1, 22, 14, 23, 1] Best cost: 5819.437 | Path: [1, 23, 17, 14, 6, 1, 11, 13, 20, 3, 16, 12, 1, 8, 18, 10, 22, 0, 1, 4, 2, 5, 1] Best cost: 5792.548 | Path: [1, 22, 10, 4, 8, 1, 11, 13, 20, 3, 17, 0, 1, 18, 12, 2, 16, 5, 1, 6, 14, 23, 1] Best cost: 5654.640 | Path: [1, 5, 16, 2, 12, 4, 1, 11, 13, 20, 3, 17, 0, 1, 18, 8, 10, 22, 1, 14, 6, 23, 1] OPTIMIZING each tour... Current: [[1, 5, 16, 2, 12, 4, 1], [1, 11, 13, 20, 3, 17, 0, 1], [1, 18, 8, 10, 22, 1], [1, 14, 6, 23, 1]] [1] Cost: 1315.123 to 1312.887 | Optimized: [1, 12, 2, 16, 5, 4, 1] [2] Cost: 1453.142 to 1431.127 | Optimized: [1, 0, 3, 17, 20, 13, 11, 1] [3] Cost: 1121.659 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] [4] Cost: 1764.716 to 1645.527 | Optimized: [1, 6, 14, 23, 1] ACO RESULTS [1/295 vol./1312.887 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Hannover Hbf --> Berlin Hbf [2/280 vol./1431.127 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mannheim Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [3/240 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/280 vol./1645.527 km] Berlin Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5497.374 km.