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 (20 vol.)
- Düsseldorf Hbf (65 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (55 vol.)
- Stuttgart Hbf (25 vol.)
- Dresden Hbf (60 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (75 vol.)
- Nürnberg Hbf (25 vol.)
- Ulm Hbf (20 vol.)
- Mannheim Hbf (50 vol.)
- Kiel Hbf (65 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (65 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1930.411 km
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Mannheim Hbf | 50 vol.
- Saarbrücken Hbf | 100 vol.
- Freiburg Hbf | 80 vol.
- Stuttgart Hbf | 25 vol.
- Ulm Hbf | 20 vol.
Tour 2
COST: 1507.756 km
LOAD: 270 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 60 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 60 vol.
Tour 3
COST: 1327.0 km
LOAD: 300 vol.
- Dortmund Hbf | 75 vol.
- Düsseldorf Hbf | 65 vol.
- Aachen Hbf | 55 vol.
- Osnabrück Hbf | 65 vol.
- Hannover Hbf | 40 vol.
Tour 4
COST: 944.451 km
LOAD: 160 vol.
- Kiel Hbf | 65 vol.
- Bremen Hbf | 95 vol.
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Mannheim Hbf | 50 vol.
- Saarbrücken Hbf | 100 vol.
- Freiburg Hbf | 80 vol.
- Stuttgart Hbf | 25 vol.
- Ulm Hbf | 20 vol.
LOAD: 270 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 60 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 60 vol.
LOAD: 300 vol.
- Dortmund Hbf | 75 vol.
- Düsseldorf Hbf | 65 vol.
- Aachen Hbf | 55 vol.
- Osnabrück Hbf | 65 vol.
- Hannover Hbf | 40 vol.
LOAD: 160 vol.
- Kiel Hbf | 65 vol.
- Bremen Hbf | 95 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: 1025 vol. | Vehicle capacity: 300 vol. Loads: [20, 0, 65, 0, 40, 55, 25, 60, 0, 60, 95, 40, 75, 25, 0, 20, 0, 50, 65, 0, 85, 100, 65, 80] ITERATION Generation: #1 Best cost: 6867.274 | Path: [1, 0, 5, 2, 12, 22, 15, 1, 7, 11, 4, 10, 18, 1, 20, 13, 9, 6, 17, 1, 21, 23, 1] Best cost: 6660.329 | Path: [1, 4, 10, 22, 12, 0, 1, 7, 11, 13, 20, 6, 15, 1, 18, 2, 5, 17, 9, 1, 21, 23, 1] Best cost: 6336.810 | Path: [1, 9, 15, 6, 17, 21, 13, 0, 1, 11, 7, 20, 23, 1, 4, 22, 10, 18, 1, 12, 2, 5, 1] Best cost: 6331.322 | Path: [1, 20, 13, 9, 15, 6, 17, 0, 1, 7, 11, 4, 10, 22, 1, 18, 2, 5, 12, 1, 21, 23, 1] Best cost: 6289.916 | Path: [1, 9, 15, 6, 17, 21, 0, 13, 1, 11, 7, 20, 23, 1, 4, 22, 12, 2, 5, 1, 18, 10, 1] Best cost: 6199.622 | Path: [1, 15, 6, 17, 21, 23, 13, 1, 7, 11, 4, 22, 10, 1, 18, 12, 2, 5, 0, 1, 20, 9, 1] Best cost: 5896.836 | Path: [1, 15, 6, 17, 21, 23, 0, 1, 7, 11, 13, 20, 9, 1, 4, 22, 12, 2, 5, 1, 18, 10, 1] OPTIMIZING each tour... Current: [[1, 15, 6, 17, 21, 23, 0, 1], [1, 7, 11, 13, 20, 9, 1], [1, 4, 22, 12, 2, 5, 1], [1, 18, 10, 1]] [1] Cost: 2041.143 to 1930.411 | Optimized: [1, 0, 17, 21, 23, 6, 15, 1] [2] Cost: 1575.868 to 1507.756 | Optimized: [1, 20, 13, 9, 11, 7, 1] [3] Cost: 1335.374 to 1327.000 | Optimized: [1, 12, 2, 5, 22, 4, 1] ACO RESULTS [1/295 vol./1930.411 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [2/270 vol./1507.756 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/300 vol./1327.000 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [4/160 vol./ 944.451 km] Berlin Hbf -> Kiel Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5709.618 km.