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: 16 customers
- Düsseldorf Hbf (45 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (40 vol.)
- München Hbf (100 vol.)
- Leipzig Hbf (60 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (55 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (80 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (85 vol.)
- Würzburg Hbf (25 vol.)
- Osnabrück Hbf (100 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1878.503 km
LOAD: 295 vol.
- Würzburg Hbf | 25 vol.
- Mannheim Hbf | 80 vol.
- Freiburg Hbf | 50 vol.
- Stuttgart Hbf | 40 vol.
- München Hbf | 100 vol.
Tour 2
COST: 1309.663 km
LOAD: 295 vol.
- Mainz Hbf | 85 vol.
- Frankfurt Hbf | 95 vol.
- Nürnberg Hbf | 55 vol.
- Leipzig Hbf | 60 vol.
Tour 3
COST: 1296.917 km
LOAD: 280 vol.
- Kiel Hbf | 65 vol.
- Osnabrück Hbf | 100 vol.
- Dortmund Hbf | 65 vol.
- Hannover Hbf | 50 vol.
Tour 4
COST: 1303.404 km
LOAD: 185 vol.
- Aachen Hbf | 80 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 45 vol.
LOAD: 295 vol.
- Würzburg Hbf | 25 vol.
- Mannheim Hbf | 80 vol.
- Freiburg Hbf | 50 vol.
- Stuttgart Hbf | 40 vol.
- München Hbf | 100 vol.
LOAD: 295 vol.
- Mainz Hbf | 85 vol.
- Frankfurt Hbf | 95 vol.
- Nürnberg Hbf | 55 vol.
- Leipzig Hbf | 60 vol.
LOAD: 280 vol.
- Kiel Hbf | 65 vol.
- Osnabrück Hbf | 100 vol.
- Dortmund Hbf | 65 vol.
- Hannover Hbf | 50 vol.
LOAD: 185 vol.
- Aachen Hbf | 80 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 45 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: 1055 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 45, 95, 50, 80, 40, 0, 0, 100, 0, 60, 65, 55, 0, 0, 60, 80, 65, 85, 25, 0, 100, 50] ITERATION Generation: #1 Best cost: 6467.763 | Path: [1, 2, 16, 5, 12, 4, 1, 11, 3, 19, 23, 1, 22, 20, 13, 9, 1, 18, 17, 6, 1] Best cost: 6417.420 | Path: [1, 6, 17, 3, 19, 1, 11, 4, 22, 12, 20, 1, 18, 2, 16, 5, 23, 1, 13, 9, 1] Best cost: 6395.393 | Path: [1, 11, 4, 22, 12, 20, 1, 18, 2, 16, 5, 23, 1, 3, 19, 17, 6, 1, 13, 9, 1] Best cost: 6156.078 | Path: [1, 12, 2, 16, 5, 20, 1, 11, 4, 22, 18, 1, 9, 13, 6, 17, 1, 3, 19, 23, 1] Best cost: 6033.718 | Path: [1, 12, 2, 16, 5, 20, 1, 11, 4, 22, 18, 1, 13, 9, 6, 17, 1, 19, 3, 23, 1] Best cost: 6014.371 | Path: [1, 12, 2, 16, 5, 20, 1, 11, 4, 22, 18, 1, 13, 9, 6, 17, 1, 3, 19, 23, 1] Generation: #2 Best cost: 6013.583 | Path: [1, 9, 6, 17, 23, 20, 1, 11, 4, 22, 12, 1, 18, 2, 16, 5, 1, 13, 19, 3, 1] Generation: #3 Best cost: 6013.477 | Path: [1, 9, 6, 17, 23, 20, 1, 11, 4, 22, 12, 1, 18, 2, 16, 5, 1, 13, 3, 19, 1] Best cost: 5956.375 | Path: [1, 18, 4, 22, 12, 1, 11, 13, 9, 6, 20, 1, 2, 16, 5, 19, 1, 3, 17, 23, 1] Best cost: 5937.379 | Path: [1, 9, 6, 17, 23, 20, 1, 11, 13, 3, 19, 1, 18, 4, 22, 12, 1, 16, 2, 5, 1] OPTIMIZING each tour... Current: [[1, 9, 6, 17, 23, 20, 1], [1, 11, 13, 3, 19, 1], [1, 18, 4, 22, 12, 1], [1, 16, 2, 5, 1]] [1] Cost: 1932.188 to 1878.503 | Optimized: [1, 20, 17, 23, 6, 9, 1] [2] Cost: 1318.548 to 1309.663 | Optimized: [1, 19, 3, 13, 11, 1] [3] Cost: 1362.863 to 1296.917 | Optimized: [1, 18, 22, 12, 4, 1] [4] Cost: 1323.780 to 1303.404 | Optimized: [1, 5, 16, 2, 1] ACO RESULTS [1/295 vol./1878.503 km] Berlin Hbf -> Würzburg Hbf -> Mannheim Hbf -> Freiburg Hbf -> Stuttgart Hbf -> München Hbf --> Berlin Hbf [2/295 vol./1309.663 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [3/280 vol./1296.917 km] Berlin Hbf -> Kiel Hbf -> Osnabrück Hbf -> Dortmund Hbf -> Hannover Hbf --> Berlin Hbf [4/185 vol./1303.404 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5788.487 km.