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: 19 customers
- Kassel-Wilhelmshöhe (40 vol.)
- Düsseldorf Hbf (60 vol.)
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (35 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (55 vol.)
- Hamburg Hbf (75 vol.)
- München Hbf (100 vol.)
- Leipzig Hbf (75 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (55 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (20 vol.)
- Saarbrücken Hbf (65 vol.)
- Osnabrück Hbf (95 vol.)
Tour 1
COST: 1523.218 km
LOAD: 285 vol.
- Frankfurt Hbf | 45 vol.
- Mainz Hbf | 20 vol.
- Karlsruhe Hbf | 95 vol.
- Stuttgart Hbf | 70 vol.
- Ulm Hbf | 55 vol.
Tour 2
COST: 1351.104 km
LOAD: 270 vol.
- Dresden Hbf | 55 vol.
- Leipzig Hbf | 75 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 100 vol.
Tour 3
COST: 1102.366 km
LOAD: 300 vol.
- Hannover Hbf | 35 vol.
- Osnabrück Hbf | 95 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 95 vol.
Tour 4
COST: 1647.355 km
LOAD: 285 vol.
- Mannheim Hbf | 85 vol.
- Saarbrücken Hbf | 65 vol.
- Aachen Hbf | 75 vol.
- Düsseldorf Hbf | 60 vol.
Tour 5
COST: 1044.694 km
LOAD: 90 vol.
- Dortmund Hbf | 50 vol.
- Kassel-Wilhelmshöhe | 40 vol.
LOAD: 285 vol.
- Frankfurt Hbf | 45 vol.
- Mainz Hbf | 20 vol.
- Karlsruhe Hbf | 95 vol.
- Stuttgart Hbf | 70 vol.
- Ulm Hbf | 55 vol.
LOAD: 270 vol.
- Dresden Hbf | 55 vol.
- Leipzig Hbf | 75 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 100 vol.
LOAD: 300 vol.
- Hannover Hbf | 35 vol.
- Osnabrück Hbf | 95 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 95 vol.
LOAD: 285 vol.
- Mannheim Hbf | 85 vol.
- Saarbrücken Hbf | 65 vol.
- Aachen Hbf | 75 vol.
- Düsseldorf Hbf | 60 vol.
LOAD: 90 vol.
- Dortmund Hbf | 50 vol.
- Kassel-Wilhelmshöhe | 40 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: 1230 vol. | Vehicle capacity: 300 vol. Loads: [40, 0, 60, 45, 35, 75, 70, 55, 75, 100, 0, 75, 50, 40, 95, 55, 0, 85, 95, 20, 0, 65, 95, 0] ITERATION Generation: #1 Best cost: 7212.050 | Path: [1, 0, 12, 2, 5, 21, 1, 11, 7, 13, 9, 19, 1, 4, 22, 8, 18, 1, 3, 17, 14, 6, 1, 15, 1] Best cost: 7001.959 | Path: [1, 7, 11, 0, 12, 2, 19, 1, 4, 22, 8, 18, 1, 13, 9, 15, 6, 1, 21, 14, 17, 3, 1, 5, 1] Best cost: 6927.549 | Path: [1, 12, 2, 5, 19, 3, 0, 1, 7, 11, 13, 6, 15, 1, 8, 18, 22, 4, 1, 14, 17, 21, 1, 9, 1] Best cost: 6917.054 | Path: [1, 12, 2, 5, 21, 19, 1, 7, 11, 13, 9, 1, 8, 18, 4, 22, 1, 0, 3, 17, 14, 1, 15, 6, 1] Generation: #2 Best cost: 6895.059 | Path: [1, 12, 2, 5, 19, 3, 0, 1, 11, 7, 13, 9, 1, 4, 22, 8, 18, 1, 15, 6, 14, 21, 1, 17, 1] Best cost: 6810.032 | Path: [1, 15, 6, 14, 3, 19, 1, 11, 7, 13, 9, 1, 8, 18, 4, 22, 1, 17, 21, 5, 2, 1, 0, 12, 1] OPTIMIZING each tour... Current: [[1, 15, 6, 14, 3, 19, 1], [1, 11, 7, 13, 9, 1], [1, 8, 18, 4, 22, 1], [1, 17, 21, 5, 2, 1], [1, 0, 12, 1]] [1] Cost: 1548.831 to 1523.218 | Optimized: [1, 3, 19, 14, 6, 15, 1] [2] Cost: 1377.326 to 1351.104 | Optimized: [1, 7, 11, 13, 9, 1] [3] Cost: 1191.637 to 1102.366 | Optimized: [1, 4, 22, 8, 18, 1] [5] Cost: 1044.883 to 1044.694 | Optimized: [1, 12, 0, 1] ACO RESULTS [1/285 vol./1523.218 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [2/270 vol./1351.104 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf [3/300 vol./1102.366 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/285 vol./1647.355 km] Berlin Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Düsseldorf Hbf --> Berlin Hbf [5/ 90 vol./1044.694 km] Berlin Hbf -> Dortmund Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6668.737 km.