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 (25 vol.)
- Düsseldorf Hbf (70 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (60 vol.)
- Aachen Hbf (85 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (40 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (70 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (90 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1446.647 km
LOAD: 295 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 90 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 100 vol.
- Stuttgart Hbf | 50 vol.
Tour 2
COST: 1224.323 km
LOAD: 280 vol.
- Hannover Hbf | 60 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 45 vol.
- Leipzig Hbf | 50 vol.
- Dresden Hbf | 35 vol.
Tour 3
COST: 1962.473 km
LOAD: 295 vol.
- Dortmund Hbf | 40 vol.
- Düsseldorf Hbf | 70 vol.
- Aachen Hbf | 85 vol.
- Saarbrücken Hbf | 30 vol.
- Freiburg Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 25 vol.
Tour 4
COST: 1357.805 km
LOAD: 270 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 70 vol.
- Nürnberg Hbf | 100 vol.
Tour 5
COST: 732.557 km
LOAD: 155 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 70 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 90 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 100 vol.
- Stuttgart Hbf | 50 vol.
LOAD: 280 vol.
- Hannover Hbf | 60 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 45 vol.
- Leipzig Hbf | 50 vol.
- Dresden Hbf | 35 vol.
LOAD: 295 vol.
- Dortmund Hbf | 40 vol.
- Düsseldorf Hbf | 70 vol.
- Aachen Hbf | 85 vol.
- Saarbrücken Hbf | 30 vol.
- Freiburg Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 25 vol.
LOAD: 270 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 70 vol.
- Nürnberg Hbf | 100 vol.
LOAD: 155 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 70 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: 1295 vol. | Vehicle capacity: 300 vol. Loads: [25, 0, 70, 30, 60, 85, 50, 35, 85, 100, 45, 50, 40, 100, 100, 70, 0, 25, 70, 90, 0, 30, 90, 45] ITERATION Generation: #1 Best cost: 7906.451 | Path: [1, 0, 19, 3, 17, 14, 21, 1, 11, 7, 13, 9, 1, 8, 18, 10, 4, 12, 1, 22, 2, 5, 6, 1, 15, 23, 1] Best cost: 7892.747 | Path: [1, 3, 19, 17, 14, 6, 1, 11, 7, 13, 9, 1, 4, 10, 8, 18, 12, 1, 0, 22, 2, 5, 21, 1, 23, 15, 1] Best cost: 7813.808 | Path: [1, 5, 2, 12, 22, 1, 11, 7, 0, 4, 10, 8, 1, 18, 17, 14, 6, 23, 1, 13, 9, 15, 21, 1, 3, 19, 1] Best cost: 7527.758 | Path: [1, 8, 10, 4, 22, 1, 7, 11, 13, 9, 1, 18, 12, 2, 5, 21, 1, 0, 3, 19, 17, 14, 1, 15, 6, 23, 1] Best cost: 7310.525 | Path: [1, 15, 6, 14, 17, 3, 0, 1, 11, 7, 13, 9, 1, 8, 18, 10, 22, 1, 4, 19, 21, 23, 12, 1, 2, 5, 1] Best cost: 7186.569 | Path: [1, 18, 8, 10, 22, 1, 11, 7, 13, 9, 1, 4, 0, 12, 2, 5, 1, 3, 19, 17, 14, 6, 1, 15, 23, 21, 1] Best cost: 7171.176 | Path: [1, 7, 11, 13, 9, 1, 8, 18, 10, 22, 1, 4, 0, 12, 2, 5, 1, 3, 19, 17, 14, 6, 1, 15, 23, 21, 1] Best cost: 6783.178 | Path: [1, 19, 3, 17, 14, 6, 1, 7, 11, 4, 10, 22, 1, 0, 12, 2, 5, 21, 23, 1, 13, 9, 15, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 19, 3, 17, 14, 6, 1], [1, 7, 11, 4, 10, 22, 1], [1, 0, 12, 2, 5, 21, 23, 1], [1, 13, 9, 15, 1], [1, 8, 18, 1]] [1] Cost: 1469.073 to 1446.647 | Optimized: [1, 3, 19, 17, 14, 6, 1] [2] Cost: 1239.698 to 1224.323 | Optimized: [1, 4, 22, 10, 11, 7, 1] [3] Cost: 1975.529 to 1962.473 | Optimized: [1, 12, 2, 5, 21, 23, 0, 1] [4] Cost: 1366.321 to 1357.805 | Optimized: [1, 9, 15, 13, 1] ACO RESULTS [1/295 vol./1446.647 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf --> Berlin Hbf [2/280 vol./1224.323 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/295 vol./1962.473 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/270 vol./1357.805 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf --> Berlin Hbf [5/155 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6723.805 km.