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
- Düsseldorf Hbf (70 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (65 vol.)
- Stuttgart Hbf (25 vol.)
- Dresden Hbf (20 vol.)
- Hamburg Hbf (50 vol.)
- München Hbf (35 vol.)
- Bremen Hbf (60 vol.)
- Leipzig Hbf (95 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (25 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (95 vol.)
- Mainz Hbf (45 vol.)
- Saarbrücken Hbf (55 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1670.245 km
LOAD: 285 vol.
- Dresden Hbf | 20 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 35 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 25 vol.
- Karlsruhe Hbf | 25 vol.
Tour 2
COST: 1113.661 km
LOAD: 300 vol.
- Leipzig Hbf | 95 vol.
- Hannover Hbf | 25 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 50 vol.
Tour 3
COST: 1800.427 km
LOAD: 295 vol.
- Saarbrücken Hbf | 55 vol.
- Freiburg Hbf | 45 vol.
- Mannheim Hbf | 95 vol.
- Mainz Hbf | 45 vol.
- Frankfurt Hbf | 55 vol.
Tour 4
COST: 1308.428 km
LOAD: 250 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 70 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 65 vol.
LOAD: 285 vol.
- Dresden Hbf | 20 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 35 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 25 vol.
- Karlsruhe Hbf | 25 vol.
LOAD: 300 vol.
- Leipzig Hbf | 95 vol.
- Hannover Hbf | 25 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 50 vol.
LOAD: 295 vol.
- Saarbrücken Hbf | 55 vol.
- Freiburg Hbf | 45 vol.
- Mannheim Hbf | 95 vol.
- Mainz Hbf | 45 vol.
- Frankfurt Hbf | 55 vol.
LOAD: 250 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 70 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 65 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: 1130 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 70, 55, 25, 65, 25, 20, 50, 35, 60, 95, 55, 85, 25, 95, 60, 95, 0, 45, 0, 55, 70, 45] ITERATION Generation: #1 Best cost: 6665.486 | Path: [1, 2, 16, 5, 12, 4, 7, 1, 11, 13, 9, 6, 14, 1, 8, 10, 22, 19, 3, 1, 21, 17, 23, 15, 1] Best cost: 6586.536 | Path: [1, 9, 15, 6, 14, 17, 4, 1, 11, 7, 10, 8, 22, 1, 12, 2, 16, 5, 19, 1, 13, 3, 21, 23, 1] Best cost: 6262.870 | Path: [1, 13, 6, 15, 14, 3, 1, 7, 11, 4, 22, 10, 1, 8, 12, 2, 16, 5, 1, 19, 17, 21, 23, 9, 1] Best cost: 6212.988 | Path: [1, 17, 14, 6, 15, 9, 7, 1, 11, 4, 22, 10, 8, 1, 13, 19, 3, 16, 12, 1, 2, 5, 21, 23, 1] Best cost: 6062.824 | Path: [1, 17, 14, 6, 15, 9, 7, 1, 11, 4, 10, 22, 8, 1, 13, 3, 19, 21, 23, 1, 12, 2, 16, 5, 1] Best cost: 5979.395 | Path: [1, 17, 14, 6, 15, 9, 7, 1, 11, 4, 22, 10, 8, 1, 13, 3, 19, 21, 23, 1, 2, 16, 5, 12, 1] Best cost: 5954.268 | Path: [1, 14, 6, 15, 9, 13, 7, 1, 11, 4, 22, 10, 8, 1, 3, 19, 17, 21, 23, 1, 16, 2, 5, 12, 1] OPTIMIZING each tour... Current: [[1, 14, 6, 15, 9, 13, 7, 1], [1, 11, 4, 22, 10, 8, 1], [1, 3, 19, 17, 21, 23, 1], [1, 16, 2, 5, 12, 1]] [1] Cost: 1684.982 to 1670.245 | Optimized: [1, 7, 13, 9, 15, 6, 14, 1] [3] Cost: 1817.585 to 1800.427 | Optimized: [1, 21, 23, 17, 19, 3, 1] [4] Cost: 1338.040 to 1308.428 | Optimized: [1, 12, 2, 16, 5, 1] ACO RESULTS [1/285 vol./1670.245 km] Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf --> Berlin Hbf [2/300 vol./1113.661 km] Berlin Hbf -> Leipzig Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/295 vol./1800.427 km] Berlin Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [4/250 vol./1308.428 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5892.761 km.