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: 17 customers
- Kassel-Wilhelmshöhe (65 vol.)
- Düsseldorf Hbf (100 vol.)
- Frankfurt Hbf (80 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (35 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (30 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (65 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (65 vol.)
- Würzburg Hbf (25 vol.)
- Osnabrück Hbf (100 vol.)
Tour 1
COST: 1308.428 km
LOAD: 290 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 100 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 100 vol.
Tour 2
COST: 1664.164 km
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Würzburg Hbf | 25 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 40 vol.
- Nürnberg Hbf | 65 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 30 vol.
Tour 3
COST: 1095.698 km
LOAD: 265 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 75 vol.
- Kiel Hbf | 90 vol.
Tour 4
COST: 1290.503 km
LOAD: 245 vol.
- Mannheim Hbf | 100 vol.
- Mainz Hbf | 65 vol.
- Frankfurt Hbf | 80 vol.
LOAD: 290 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 100 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 100 vol.
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Würzburg Hbf | 25 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 40 vol.
- Nürnberg Hbf | 65 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 30 vol.
LOAD: 265 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 75 vol.
- Kiel Hbf | 90 vol.
LOAD: 245 vol.
- Mannheim Hbf | 100 vol.
- Mainz Hbf | 65 vol.
- Frankfurt Hbf | 80 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: 1080 vol. | Vehicle capacity: 300 vol. Loads: [65, 0, 100, 80, 0, 100, 20, 35, 0, 0, 75, 30, 55, 65, 0, 40, 35, 100, 90, 65, 25, 0, 100, 0] ITERATION Generation: #1 Best cost: 6204.250 | Path: [1, 0, 12, 2, 16, 6, 20, 1, 11, 7, 13, 17, 19, 1, 18, 10, 22, 1, 3, 5, 15, 1] Best cost: 6075.655 | Path: [1, 3, 19, 17, 6, 20, 1, 7, 11, 0, 22, 12, 1, 18, 10, 5, 16, 1, 13, 15, 2, 1] Best cost: 5828.537 | Path: [1, 7, 11, 0, 19, 3, 20, 1, 18, 10, 22, 16, 1, 13, 15, 6, 17, 12, 1, 2, 5, 1] Best cost: 5737.773 | Path: [1, 5, 2, 16, 12, 1, 11, 7, 0, 3, 19, 20, 1, 13, 15, 6, 17, 10, 1, 22, 18, 1] Best cost: 5729.439 | Path: [1, 3, 19, 17, 6, 20, 1, 11, 7, 13, 15, 16, 12, 1, 0, 2, 5, 1, 18, 10, 22, 1] Best cost: 5554.878 | Path: [1, 15, 6, 17, 3, 20, 11, 1, 7, 13, 19, 16, 2, 1, 18, 10, 22, 1, 0, 12, 5, 1] Best cost: 5486.048 | Path: [1, 5, 16, 2, 12, 1, 7, 11, 20, 3, 19, 6, 15, 1, 18, 10, 22, 1, 13, 17, 0, 1] Generation: #5 Best cost: 5474.530 | Path: [1, 5, 16, 2, 12, 1, 11, 7, 13, 20, 6, 15, 0, 1, 18, 10, 22, 1, 17, 19, 3, 1] OPTIMIZING each tour... Current: [[1, 5, 16, 2, 12, 1], [1, 11, 7, 13, 20, 6, 15, 0, 1], [1, 18, 10, 22, 1], [1, 17, 19, 3, 1]] [1] Cost: 1310.663 to 1308.428 | Optimized: [1, 12, 2, 16, 5, 1] [2] Cost: 1771.490 to 1664.164 | Optimized: [1, 0, 20, 6, 15, 13, 7, 11, 1] [3] Cost: 1101.874 to 1095.698 | Optimized: [1, 22, 10, 18, 1] ACO RESULTS [1/290 vol./1308.428 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf [2/280 vol./1664.164 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Würzburg Hbf -> Stuttgart Hbf -> Ulm Hbf -> Nürnberg Hbf -> Dresden Hbf -> Leipzig Hbf --> Berlin Hbf [3/265 vol./1095.698 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [4/245 vol./1290.503 km] Berlin Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5358.793 km.