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: 22 customers
- Kassel-Wilhelmshöhe (100 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (35 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (55 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (65 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (55 vol.)
- Dortmund Hbf (100 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (45 vol.)
- Köln Hbf (50 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (55 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (75 vol.)
- Saarbrücken Hbf (95 vol.)
- Osnabrück Hbf (65 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1446.647 km
LOAD: 300 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 35 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 100 vol.
- Stuttgart Hbf | 50 vol.
Tour 2
COST: 1264.264 km
LOAD: 295 vol.
- Dresden Hbf | 55 vol.
- Leipzig Hbf | 55 vol.
- Hannover Hbf | 35 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 55 vol.
Tour 3
COST: 1175.326 km
LOAD: 295 vol.
- Dortmund Hbf | 100 vol.
- Düsseldorf Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 100 vol.
Tour 4
COST: 1912.186 km
LOAD: 295 vol.
- Osnabrück Hbf | 65 vol.
- Köln Hbf | 50 vol.
- Saarbrücken Hbf | 95 vol.
- Freiburg Hbf | 60 vol.
- Nürnberg Hbf | 25 vol.
Tour 5
COST: 1403.95 km
LOAD: 185 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 45 vol.
- Würzburg Hbf | 75 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 35 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 100 vol.
- Stuttgart Hbf | 50 vol.
LOAD: 295 vol.
- Dresden Hbf | 55 vol.
- Leipzig Hbf | 55 vol.
- Hannover Hbf | 35 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 55 vol.
LOAD: 295 vol.
- Dortmund Hbf | 100 vol.
- Düsseldorf Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 100 vol.
LOAD: 295 vol.
- Osnabrück Hbf | 65 vol.
- Köln Hbf | 50 vol.
- Saarbrücken Hbf | 95 vol.
- Freiburg Hbf | 60 vol.
- Nürnberg Hbf | 25 vol.
LOAD: 185 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 45 vol.
- Würzburg Hbf | 75 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: 1370 vol. | Vehicle capacity: 300 vol. Loads: [100, 0, 95, 30, 35, 0, 50, 55, 40, 65, 55, 55, 100, 25, 100, 45, 50, 85, 55, 35, 75, 95, 65, 60] ITERATION Generation: #1 Best cost: 7913.309 | Path: [1, 0, 12, 2, 1, 7, 11, 13, 20, 6, 19, 1, 8, 18, 10, 22, 4, 16, 1, 3, 17, 14, 23, 1, 9, 15, 21, 1] Best cost: 7724.569 | Path: [1, 3, 19, 17, 14, 6, 1, 11, 7, 20, 13, 9, 1, 4, 10, 22, 12, 8, 1, 18, 0, 16, 2, 1, 21, 23, 15, 1] Best cost: 7684.326 | Path: [1, 4, 22, 12, 2, 1, 11, 7, 20, 13, 9, 1, 8, 18, 10, 16, 3, 19, 1, 0, 17, 14, 1, 15, 6, 23, 21, 1] Best cost: 7658.101 | Path: [1, 23, 14, 6, 15, 13, 1, 11, 7, 20, 3, 19, 16, 1, 4, 10, 8, 18, 22, 1, 0, 12, 2, 1, 9, 17, 21, 1] Best cost: 7312.056 | Path: [1, 9, 15, 6, 14, 19, 1, 11, 7, 13, 20, 3, 16, 1, 8, 18, 10, 22, 4, 1, 0, 12, 2, 1, 17, 21, 23, 1] Generation: #2 Best cost: 7304.905 | Path: [1, 9, 15, 6, 14, 3, 1, 11, 7, 13, 20, 19, 16, 1, 8, 18, 10, 22, 4, 1, 0, 12, 2, 1, 17, 21, 23, 1] Best cost: 7236.855 | Path: [1, 19, 3, 17, 14, 6, 1, 7, 11, 4, 10, 8, 18, 1, 0, 12, 2, 1, 22, 16, 21, 23, 13, 1, 20, 15, 9, 1] Generation: #3 Best cost: 7214.429 | Path: [1, 3, 19, 17, 14, 6, 1, 7, 11, 4, 10, 8, 18, 1, 0, 12, 2, 1, 22, 16, 21, 23, 13, 1, 20, 15, 9, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 17, 14, 6, 1], [1, 7, 11, 4, 10, 8, 18, 1], [1, 0, 12, 2, 1], [1, 22, 16, 21, 23, 13, 1], [1, 20, 15, 9, 1]] [3] Cost: 1176.836 to 1175.326 | Optimized: [1, 12, 2, 0, 1] [5] Cost: 1414.496 to 1403.950 | Optimized: [1, 9, 15, 20, 1] ACO RESULTS [1/300 vol./1446.647 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf --> Berlin Hbf [2/295 vol./1264.264 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/295 vol./1175.326 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/295 vol./1912.186 km] Berlin Hbf -> Osnabrück Hbf -> Köln Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Nürnberg Hbf --> Berlin Hbf [5/185 vol./1403.950 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Würzburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7202.373 km.