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 (95 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (100 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (60 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (25 vol.)
- Dortmund Hbf (45 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (25 vol.)
- Ulm Hbf (90 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (50 vol.)
- Würzburg Hbf (100 vol.)
- Saarbrücken Hbf (40 vol.)
- Osnabrück Hbf (40 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1447.27 km
LOAD: 290 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 90 vol.
- Stuttgart Hbf | 100 vol.
Tour 2
COST: 1255.116 km
LOAD: 295 vol.
- Dresden Hbf | 95 vol.
- Hannover Hbf | 95 vol.
- Bremen Hbf | 25 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 20 vol.
Tour 3
COST: 1707.768 km
LOAD: 295 vol.
- Saarbrücken Hbf | 40 vol.
- Aachen Hbf | 45 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 95 vol.
- Dortmund Hbf | 45 vol.
- Osnabrück Hbf | 40 vol.
Tour 4
COST: 1674.135 km
LOAD: 275 vol.
- Frankfurt Hbf | 45 vol.
- Mainz Hbf | 50 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 25 vol.
- Freiburg Hbf | 70 vol.
Tour 5
COST: 1149.824 km
LOAD: 275 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Würzburg Hbf | 100 vol.
- Nürnberg Hbf | 80 vol.
LOAD: 290 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 90 vol.
- Stuttgart Hbf | 100 vol.
LOAD: 295 vol.
- Dresden Hbf | 95 vol.
- Hannover Hbf | 95 vol.
- Bremen Hbf | 25 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 20 vol.
LOAD: 295 vol.
- Saarbrücken Hbf | 40 vol.
- Aachen Hbf | 45 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 95 vol.
- Dortmund Hbf | 45 vol.
- Osnabrück Hbf | 40 vol.
LOAD: 275 vol.
- Frankfurt Hbf | 45 vol.
- Mainz Hbf | 50 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 25 vol.
- Freiburg Hbf | 70 vol.
LOAD: 275 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Würzburg Hbf | 100 vol.
- Nürnberg Hbf | 80 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: 1430 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 95, 45, 95, 45, 100, 95, 60, 100, 25, 0, 45, 80, 25, 90, 30, 85, 20, 50, 100, 40, 40, 70] ITERATION Generation: #1 Best cost: 8121.400 | Path: [1, 0, 22, 10, 4, 12, 1, 7, 13, 20, 14, 1, 8, 18, 2, 16, 5, 3, 1, 19, 17, 21, 23, 1, 15, 6, 9, 1] Best cost: 8093.285 | Path: [1, 3, 19, 17, 14, 15, 1, 7, 13, 20, 10, 1, 4, 22, 12, 2, 18, 1, 8, 16, 5, 21, 23, 1, 0, 6, 9, 1] Best cost: 7865.627 | Path: [1, 5, 16, 2, 12, 22, 10, 18, 1, 7, 0, 4, 1, 8, 13, 20, 3, 1, 6, 15, 14, 17, 1, 19, 21, 23, 9, 1] Best cost: 7857.223 | Path: [1, 7, 9, 15, 1, 4, 10, 8, 18, 22, 12, 1, 0, 19, 3, 17, 14, 1, 20, 13, 6, 1, 16, 2, 5, 21, 23, 1] Best cost: 7619.471 | Path: [1, 8, 18, 4, 10, 22, 12, 1, 7, 13, 20, 14, 1, 0, 2, 16, 5, 1, 9, 15, 6, 1, 3, 19, 17, 21, 23, 1] Best cost: 7548.235 | Path: [1, 18, 8, 10, 4, 22, 12, 1, 7, 3, 19, 17, 14, 1, 20, 13, 9, 1, 0, 2, 16, 5, 1, 15, 6, 23, 21, 1] Best cost: 7476.772 | Path: [1, 5, 16, 2, 12, 22, 10, 18, 1, 7, 0, 4, 1, 8, 17, 14, 6, 1, 20, 13, 9, 1, 3, 19, 21, 23, 15, 1] Best cost: 7436.853 | Path: [1, 18, 8, 10, 22, 12, 2, 1, 7, 0, 4, 1, 3, 19, 17, 14, 15, 1, 13, 20, 6, 1, 9, 23, 21, 5, 16, 1] Generation: #3 Best cost: 7254.195 | Path: [1, 6, 15, 9, 1, 7, 4, 10, 8, 18, 1, 22, 12, 2, 16, 5, 21, 1, 3, 19, 17, 14, 23, 1, 0, 20, 13, 1] OPTIMIZING each tour... Current: [[1, 6, 15, 9, 1], [1, 7, 4, 10, 8, 18, 1], [1, 22, 12, 2, 16, 5, 21, 1], [1, 3, 19, 17, 14, 23, 1], [1, 0, 20, 13, 1]] [1] Cost: 1459.136 to 1447.270 | Optimized: [1, 9, 15, 6, 1] [3] Cost: 1715.984 to 1707.768 | Optimized: [1, 21, 5, 16, 2, 12, 22, 1] ACO RESULTS [1/290 vol./1447.270 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf --> Berlin Hbf [2/295 vol./1255.116 km] Berlin Hbf -> Dresden Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/295 vol./1707.768 km] Berlin Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Berlin Hbf [4/275 vol./1674.135 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [5/275 vol./1149.824 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7234.113 km.