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: 21 customers
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (70 vol.)
- Hamburg Hbf (45 vol.)
- München Hbf (65 vol.)
- Bremen Hbf (80 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (30 vol.)
- Ulm Hbf (75 vol.)
- Köln Hbf (75 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (30 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1113.837 km
LOAD: 285 vol.
- Hannover Hbf | 95 vol.
- Osnabrück Hbf | 30 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 35 vol.
Tour 2
COST: 1364.79 km
LOAD: 285 vol.
- Frankfurt Hbf | 45 vol.
- Mainz Hbf | 35 vol.
- Mannheim Hbf | 85 vol.
- Würzburg Hbf | 40 vol.
- Leipzig Hbf | 80 vol.
Tour 3
COST: 1857.095 km
LOAD: 300 vol.
- Ulm Hbf | 75 vol.
- Stuttgart Hbf | 70 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 50 vol.
Tour 4
COST: 1308.428 km
LOAD: 280 vol.
- Dortmund Hbf | 90 vol.
- Düsseldorf Hbf | 65 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 50 vol.
Tour 5
COST: 1189.939 km
LOAD: 165 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 65 vol.
LOAD: 285 vol.
- Hannover Hbf | 95 vol.
- Osnabrück Hbf | 30 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 35 vol.
LOAD: 285 vol.
- Frankfurt Hbf | 45 vol.
- Mainz Hbf | 35 vol.
- Mannheim Hbf | 85 vol.
- Würzburg Hbf | 40 vol.
- Leipzig Hbf | 80 vol.
LOAD: 300 vol.
- Ulm Hbf | 75 vol.
- Stuttgart Hbf | 70 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 50 vol.
LOAD: 280 vol.
- Dortmund Hbf | 90 vol.
- Düsseldorf Hbf | 65 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 50 vol.
LOAD: 165 vol.
- Nürnberg Hbf | 100 vol.
- München 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: 1315 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 65, 45, 95, 50, 70, 0, 45, 65, 80, 80, 90, 100, 30, 75, 75, 85, 35, 35, 40, 50, 30, 75] ITERATION Generation: #1 Best cost: 7573.045 | Path: [1, 2, 16, 5, 12, 1, 11, 4, 10, 8, 1, 18, 22, 3, 19, 17, 14, 20, 1, 13, 9, 15, 21, 1, 6, 23, 1] Best cost: 7406.581 | Path: [1, 3, 19, 17, 14, 6, 22, 1, 11, 20, 13, 15, 1, 12, 2, 16, 5, 1, 4, 10, 8, 18, 1, 9, 23, 21, 1] Best cost: 7292.616 | Path: [1, 5, 16, 2, 12, 1, 11, 13, 20, 3, 19, 1, 8, 18, 10, 4, 22, 1, 9, 15, 6, 14, 21, 1, 23, 17, 1] Best cost: 7223.505 | Path: [1, 18, 8, 10, 22, 4, 1, 11, 3, 19, 17, 14, 1, 13, 20, 6, 15, 1, 2, 16, 5, 12, 1, 9, 23, 21, 1] Best cost: 7157.077 | Path: [1, 5, 16, 2, 12, 1, 8, 18, 10, 22, 4, 1, 11, 13, 20, 19, 3, 1, 9, 15, 6, 14, 21, 1, 17, 23, 1] Best cost: 7129.102 | Path: [1, 12, 2, 16, 5, 1, 11, 13, 20, 3, 19, 1, 4, 22, 10, 8, 18, 1, 9, 15, 6, 14, 21, 1, 17, 23, 1] Best cost: 7006.688 | Path: [1, 8, 18, 10, 4, 22, 1, 11, 20, 3, 19, 17, 1, 15, 6, 14, 23, 21, 1, 12, 2, 16, 5, 1, 13, 9, 1] OPTIMIZING each tour... Current: [[1, 8, 18, 10, 4, 22, 1], [1, 11, 20, 3, 19, 17, 1], [1, 15, 6, 14, 23, 21, 1], [1, 12, 2, 16, 5, 1], [1, 13, 9, 1]] [1] Cost: 1268.622 to 1113.837 | Optimized: [1, 4, 22, 10, 8, 18, 1] [2] Cost: 1382.604 to 1364.790 | Optimized: [1, 3, 19, 17, 20, 11, 1] ACO RESULTS [1/285 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [2/285 vol./1364.790 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Würzburg Hbf -> Leipzig Hbf --> Berlin Hbf [3/300 vol./1857.095 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [4/280 vol./1308.428 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf [5/165 vol./1189.939 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6834.089 km.