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: 20 customers
- Kassel-Wilhelmshöhe (30 vol.)
- Düsseldorf Hbf (65 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (35 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (50 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (55 vol.)
- Ulm Hbf (45 vol.)
- Köln Hbf (45 vol.)
- Mannheim Hbf (60 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (55 vol.)
- Osnabrück Hbf (40 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1610.39 km
LOAD: 295 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 35 vol.
- Nürnberg Hbf | 55 vol.
- Würzburg Hbf | 40 vol.
- Mainz Hbf | 95 vol.
- Köln Hbf | 45 vol.
Tour 2
COST: 1327.0 km
LOAD: 285 vol.
- Dortmund Hbf | 50 vol.
- Düsseldorf Hbf | 65 vol.
- Aachen Hbf | 35 vol.
- Osnabrück Hbf | 40 vol.
- Hannover Hbf | 95 vol.
Tour 3
COST: 2046.809 km
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 30 vol.
- Mannheim Hbf | 60 vol.
- Saarbrücken Hbf | 55 vol.
- Freiburg Hbf | 20 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 45 vol.
- München Hbf | 50 vol.
Tour 4
COST: 789.644 km
LOAD: 145 vol.
- Hamburg Hbf | 100 vol.
- Bremen Hbf | 45 vol.
LOAD: 295 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 35 vol.
- Nürnberg Hbf | 55 vol.
- Würzburg Hbf | 40 vol.
- Mainz Hbf | 95 vol.
- Köln Hbf | 45 vol.
LOAD: 285 vol.
- Dortmund Hbf | 50 vol.
- Düsseldorf Hbf | 65 vol.
- Aachen Hbf | 35 vol.
- Osnabrück Hbf | 40 vol.
- Hannover Hbf | 95 vol.
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 30 vol.
- Mannheim Hbf | 60 vol.
- Saarbrücken Hbf | 55 vol.
- Freiburg Hbf | 20 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 45 vol.
- München Hbf | 50 vol.
LOAD: 145 vol.
- Hamburg Hbf | 100 vol.
- Bremen 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: 1005 vol. | Vehicle capacity: 300 vol. Loads: [30, 0, 65, 0, 95, 35, 20, 25, 100, 50, 45, 35, 50, 55, 0, 45, 45, 60, 0, 95, 40, 55, 40, 20] ITERATION Generation: #1 Best cost: 7243.912 | Path: [1, 0, 19, 17, 6, 15, 9, 1, 11, 7, 13, 20, 2, 16, 5, 1, 8, 4, 22, 10, 23, 1, 12, 21, 1] Best cost: 7049.289 | Path: [1, 4, 10, 8, 22, 6, 1, 7, 11, 13, 20, 19, 16, 1, 0, 12, 2, 5, 21, 17, 1, 9, 15, 23, 1] Best cost: 6398.732 | Path: [1, 6, 15, 9, 13, 20, 17, 23, 1, 11, 7, 4, 10, 8, 1, 0, 12, 2, 16, 5, 22, 1, 19, 21, 1] Best cost: 6229.193 | Path: [1, 9, 15, 6, 17, 19, 0, 1, 7, 11, 13, 20, 21, 23, 5, 1, 8, 10, 4, 22, 1, 12, 2, 16, 1] Best cost: 6194.362 | Path: [1, 13, 20, 19, 17, 6, 23, 1, 7, 11, 0, 12, 2, 16, 5, 1, 8, 10, 22, 4, 1, 9, 15, 21, 1] Best cost: 6078.128 | Path: [1, 9, 15, 6, 17, 19, 23, 1, 7, 11, 4, 10, 8, 1, 22, 12, 2, 16, 5, 21, 1, 13, 20, 0, 1] Best cost: 6053.016 | Path: [1, 20, 19, 17, 21, 23, 6, 1, 11, 7, 12, 2, 16, 5, 22, 1, 0, 4, 10, 8, 1, 13, 9, 15, 1] Best cost: 5954.206 | Path: [1, 23, 21, 19, 17, 6, 15, 1, 7, 11, 0, 12, 2, 16, 5, 1, 4, 22, 10, 8, 1, 20, 13, 9, 1] Best cost: 5923.037 | Path: [1, 19, 17, 21, 23, 6, 15, 1, 7, 11, 4, 8, 10, 1, 22, 12, 2, 16, 5, 0, 1, 20, 13, 9, 1] Best cost: 5843.870 | Path: [1, 19, 17, 21, 23, 6, 15, 1, 7, 11, 0, 12, 2, 16, 5, 1, 4, 22, 10, 8, 1, 13, 20, 9, 1] Generation: #10 Best cost: 5808.439 | Path: [1, 11, 7, 13, 20, 19, 16, 1, 4, 22, 12, 2, 5, 1, 0, 17, 21, 23, 6, 15, 9, 1, 8, 10, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 13, 20, 19, 16, 1], [1, 4, 22, 12, 2, 5, 1], [1, 0, 17, 21, 23, 6, 15, 9, 1], [1, 8, 10, 1]] [1] Cost: 1636.612 to 1610.390 | Optimized: [1, 7, 11, 13, 20, 19, 16, 1] [2] Cost: 1335.374 to 1327.000 | Optimized: [1, 12, 2, 5, 22, 4, 1] ACO RESULTS [1/295 vol./1610.390 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> Würzburg Hbf -> Mainz Hbf -> Köln Hbf --> Berlin Hbf [2/285 vol./1327.000 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [3/280 vol./2046.809 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Stuttgart Hbf -> Ulm Hbf -> München Hbf --> Berlin Hbf [4/145 vol./ 789.644 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5773.843 km.