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: 15 customers
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (95 vol.)
- Hamburg Hbf (25 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (50 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (80 vol.)
- Ulm Hbf (70 vol.)
- Mannheim Hbf (20 vol.)
- Mainz Hbf (65 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1427.684 km
LOAD: 290 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 35 vol.
- Aachen Hbf | 50 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 50 vol.
- Hamburg Hbf | 25 vol.
Tour 2
COST: 1859.789 km
LOAD: 295 vol.
- Hannover Hbf | 40 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 65 vol.
- Mannheim Hbf | 20 vol.
- Freiburg Hbf | 70 vol.
- Ulm Hbf | 70 vol.
Tour 3
COST: 1441.931 km
LOAD: 255 vol.
- München Hbf | 80 vol.
- Stuttgart Hbf | 95 vol.
- Nürnberg Hbf | 80 vol.
LOAD: 290 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 35 vol.
- Aachen Hbf | 50 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 50 vol.
- Hamburg Hbf | 25 vol.
LOAD: 295 vol.
- Hannover Hbf | 40 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 65 vol.
- Mannheim Hbf | 20 vol.
- Freiburg Hbf | 70 vol.
- Ulm Hbf | 70 vol.
LOAD: 255 vol.
- München Hbf | 80 vol.
- Stuttgart Hbf | 95 vol.
- Nürnberg 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: 840 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 35, 30, 40, 50, 95, 0, 25, 80, 50, 0, 60, 80, 0, 70, 0, 20, 0, 65, 0, 0, 70, 70] ITERATION Generation: #1 Best cost: 6119.382 | Path: [1, 2, 12, 22, 10, 4, 8, 17, 1, 9, 15, 6, 3, 1, 13, 19, 5, 23, 1] Best cost: 5061.806 | Path: [1, 3, 19, 17, 6, 15, 1, 4, 10, 22, 12, 2, 8, 1, 13, 9, 23, 5, 1] Best cost: 4811.364 | Path: [1, 5, 2, 12, 22, 10, 8, 1, 4, 19, 3, 17, 6, 1, 13, 9, 15, 23, 1] Best cost: 4788.937 | Path: [1, 5, 2, 12, 22, 10, 8, 1, 4, 3, 19, 17, 6, 1, 13, 9, 15, 23, 1] Best cost: 4748.345 | Path: [1, 2, 5, 12, 22, 10, 8, 1, 4, 3, 19, 17, 23, 15, 1, 13, 9, 6, 1] Best cost: 4746.369 | Path: [1, 6, 17, 3, 19, 5, 2, 1, 8, 10, 22, 12, 4, 1, 13, 9, 15, 23, 1] Best cost: 4740.715 | Path: [1, 5, 2, 12, 22, 10, 8, 1, 4, 3, 19, 17, 23, 15, 1, 13, 9, 6, 1] OPTIMIZING each tour... Current: [[1, 5, 2, 12, 22, 10, 8, 1], [1, 4, 3, 19, 17, 23, 15, 1], [1, 13, 9, 6, 1]] [1] Cost: 1430.479 to 1427.684 | Optimized: [1, 12, 2, 5, 22, 10, 8, 1] [3] Cost: 1450.447 to 1441.931 | Optimized: [1, 9, 6, 13, 1] ACO RESULTS [1/290 vol./1427.684 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [2/295 vol./1859.789 km] Berlin Hbf -> Hannover Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Freiburg Hbf -> Ulm Hbf --> Berlin Hbf [3/255 vol./1441.931 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4729.404 km.