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
- Kassel-Wilhelmshöhe (30 vol.)
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (25 vol.)
- Hannover Hbf (90 vol.)
- Aachen Hbf (20 vol.)
- Stuttgart Hbf (55 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (20 vol.)
- Leipzig Hbf (70 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (50 vol.)
- Karlsruhe Hbf (70 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (85 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (75 vol.)
- Osnabrück Hbf (30 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1715.037 km
LOAD: 300 vol.
- Frankfurt Hbf | 25 vol.
- Saarbrücken Hbf | 75 vol.
- Aachen Hbf | 20 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 35 vol.
- Dortmund Hbf | 20 vol.
- Osnabrück Hbf | 30 vol.
Tour 2
COST: 1312.378 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 30 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 50 vol.
- Leipzig Hbf | 70 vol.
- Dresden Hbf | 70 vol.
Tour 3
COST: 1557.619 km
LOAD: 290 vol.
- Kiel Hbf | 95 vol.
- Hamburg Hbf | 20 vol.
- Hannover Hbf | 90 vol.
- Mainz Hbf | 85 vol.
Tour 4
COST: 1951.465 km
LOAD: 300 vol.
- München Hbf | 20 vol.
- Stuttgart Hbf | 55 vol.
- Karlsruhe Hbf | 70 vol.
- Mannheim Hbf | 70 vol.
- Freiburg Hbf | 85 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 25 vol.
- Saarbrücken Hbf | 75 vol.
- Aachen Hbf | 20 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 35 vol.
- Dortmund Hbf | 20 vol.
- Osnabrück Hbf | 30 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 30 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 50 vol.
- Leipzig Hbf | 70 vol.
- Dresden Hbf | 70 vol.
LOAD: 290 vol.
- Kiel Hbf | 95 vol.
- Hamburg Hbf | 20 vol.
- Hannover Hbf | 90 vol.
- Mainz Hbf | 85 vol.
LOAD: 300 vol.
- München Hbf | 20 vol.
- Stuttgart Hbf | 55 vol.
- Karlsruhe Hbf | 70 vol.
- Mannheim Hbf | 70 vol.
- Freiburg Hbf | 85 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: 1190 vol. | Vehicle capacity: 300 vol. Loads: [30, 0, 35, 25, 90, 20, 55, 70, 20, 20, 0, 70, 20, 50, 70, 0, 95, 70, 95, 85, 80, 75, 30, 85] ITERATION Generation: #1 Best cost: 8829.932 | Path: [1, 0, 22, 12, 2, 16, 5, 3, 9, 8, 1, 11, 7, 13, 20, 1, 4, 18, 17, 1, 19, 21, 14, 6, 1, 23, 1] Best cost: 7433.747 | Path: [1, 2, 16, 5, 12, 22, 4, 1, 11, 7, 13, 20, 3, 1, 18, 8, 0, 19, 17, 1, 6, 14, 23, 21, 1, 9, 1] Best cost: 7142.472 | Path: [1, 9, 13, 20, 3, 19, 0, 1, 11, 7, 4, 22, 12, 5, 1, 18, 8, 2, 16, 6, 1, 21, 17, 14, 23, 1] Best cost: 7036.549 | Path: [1, 12, 2, 16, 5, 19, 3, 9, 1, 11, 7, 13, 20, 0, 1, 4, 8, 18, 22, 6, 1, 17, 14, 23, 21, 1] Best cost: 6924.909 | Path: [1, 2, 16, 5, 12, 22, 4, 1, 11, 7, 0, 19, 3, 9, 1, 8, 18, 20, 6, 13, 1, 17, 14, 21, 23, 1] Best cost: 6812.745 | Path: [1, 5, 2, 16, 12, 22, 4, 1, 11, 7, 20, 3, 6, 1, 8, 18, 0, 19, 17, 1, 13, 9, 14, 21, 23, 1] Best cost: 6791.727 | Path: [1, 2, 16, 5, 12, 22, 4, 1, 7, 11, 3, 19, 0, 8, 1, 18, 20, 13, 9, 6, 1, 17, 14, 23, 21, 1] Best cost: 6651.099 | Path: [1, 8, 18, 4, 22, 12, 2, 1, 7, 11, 0, 20, 13, 1, 21, 14, 17, 19, 1, 16, 5, 3, 23, 6, 9, 1] Best cost: 6648.419 | Path: [1, 12, 2, 16, 5, 19, 3, 9, 1, 7, 11, 0, 22, 4, 1, 8, 18, 20, 6, 13, 1, 17, 14, 23, 21, 1] Generation: #2 Best cost: 6580.307 | Path: [1, 22, 12, 2, 16, 5, 21, 3, 1, 11, 7, 13, 20, 0, 1, 18, 8, 4, 19, 1, 9, 6, 14, 17, 23, 1] OPTIMIZING each tour... Current: [[1, 22, 12, 2, 16, 5, 21, 3, 1], [1, 11, 7, 13, 20, 0, 1], [1, 18, 8, 4, 19, 1], [1, 9, 6, 14, 17, 23, 1]] [1] Cost: 1727.717 to 1715.037 | Optimized: [1, 3, 21, 5, 16, 2, 12, 22, 1] [2] Cost: 1343.506 to 1312.378 | Optimized: [1, 0, 20, 13, 11, 7, 1] ACO RESULTS [1/300 vol./1715.037 km] Berlin Hbf -> Frankfurt Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Berlin Hbf [2/300 vol./1312.378 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/290 vol./1557.619 km] Berlin Hbf -> Kiel Hbf -> Hamburg Hbf -> Hannover Hbf -> Mainz Hbf --> Berlin Hbf [4/300 vol./1951.465 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6536.499 km.