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 (85 vol.)
- Frankfurt Hbf (20 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (60 vol.)
- München Hbf (60 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (70 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (90 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (55 vol.)
- Würzburg Hbf (100 vol.)
- Osnabrück Hbf (95 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1975.262 km
LOAD: 300 vol.
- Frankfurt Hbf | 20 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 90 vol.
- Freiburg Hbf | 45 vol.
- Köln Hbf | 30 vol.
- Hamburg Hbf | 60 vol.
Tour 2
COST: 1187.501 km
LOAD: 255 vol.
- Würzburg Hbf | 100 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 35 vol.
Tour 3
COST: 1156.449 km
LOAD: 250 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 85 vol.
- Osnabrück Hbf | 95 vol.
Tour 4
COST: 1447.27 km
LOAD: 215 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 60 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 20 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 90 vol.
- Freiburg Hbf | 45 vol.
- Köln Hbf | 30 vol.
- Hamburg Hbf | 60 vol.
LOAD: 255 vol.
- Würzburg Hbf | 100 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 35 vol.
LOAD: 250 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 85 vol.
- Osnabrück Hbf | 95 vol.
LOAD: 215 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 60 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: 1020 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 85, 20, 0, 0, 60, 35, 60, 60, 0, 40, 70, 80, 90, 95, 30, 55, 0, 0, 100, 0, 95, 45] ITERATION Generation: #1 Best cost: 6632.784 | Path: [1, 2, 16, 12, 22, 3, 1, 7, 11, 13, 20, 23, 1, 8, 14, 6, 17, 1, 15, 9, 1] Best cost: 6373.571 | Path: [1, 8, 22, 12, 16, 3, 1, 7, 11, 20, 13, 23, 1, 2, 17, 14, 6, 1, 9, 15, 1] Best cost: 6219.562 | Path: [1, 17, 14, 6, 15, 1, 11, 7, 20, 3, 16, 12, 1, 8, 22, 2, 23, 1, 13, 9, 1] Best cost: 6216.673 | Path: [1, 23, 14, 6, 15, 1, 11, 7, 13, 20, 3, 1, 8, 22, 12, 16, 1, 9, 17, 2, 1] Best cost: 6201.068 | Path: [1, 22, 12, 2, 16, 3, 1, 7, 11, 13, 20, 23, 1, 8, 17, 14, 6, 1, 9, 15, 1] Best cost: 5807.899 | Path: [1, 23, 14, 17, 3, 16, 8, 1, 7, 11, 13, 20, 1, 22, 12, 2, 1, 9, 15, 6, 1] OPTIMIZING each tour... Current: [[1, 23, 14, 17, 3, 16, 8, 1], [1, 7, 11, 13, 20, 1], [1, 22, 12, 2, 1], [1, 9, 15, 6, 1]] [1] Cost: 2000.239 to 1975.262 | Optimized: [1, 3, 17, 14, 23, 16, 8, 1] [2] Cost: 1190.097 to 1187.501 | Optimized: [1, 20, 13, 11, 7, 1] [3] Cost: 1170.293 to 1156.449 | Optimized: [1, 12, 2, 22, 1] ACO RESULTS [1/300 vol./1975.262 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Köln Hbf -> Hamburg Hbf --> Berlin Hbf [2/255 vol./1187.501 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/250 vol./1156.449 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf --> Berlin Hbf [4/215 vol./1447.270 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5766.482 km.