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 (45 vol.)
- Düsseldorf Hbf (20 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (20 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (85 vol.)
- Dresden Hbf (40 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (40 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (65 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (30 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (45 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1098.074 km
LOAD: 285 vol.
- Dresden Hbf | 40 vol.
- Leipzig Hbf | 100 vol.
- Hannover Hbf | 20 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 90 vol.
Tour 2
COST: 1988.832 km
LOAD: 300 vol.
- Mannheim Hbf | 20 vol.
- Saarbrücken Hbf | 20 vol.
- Aachen Hbf | 60 vol.
- Köln Hbf | 65 vol.
- Düsseldorf Hbf | 20 vol.
- Dortmund Hbf | 40 vol.
- Osnabrück Hbf | 45 vol.
- Kiel Hbf | 30 vol.
Tour 3
COST: 1321.349 km
LOAD: 270 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 60 vol.
- Würzburg Hbf | 25 vol.
- Nürnberg Hbf | 40 vol.
Tour 4
COST: 1818.365 km
LOAD: 255 vol.
- München Hbf | 40 vol.
- Stuttgart Hbf | 85 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 65 vol.
LOAD: 285 vol.
- Dresden Hbf | 40 vol.
- Leipzig Hbf | 100 vol.
- Hannover Hbf | 20 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 90 vol.
LOAD: 300 vol.
- Mannheim Hbf | 20 vol.
- Saarbrücken Hbf | 20 vol.
- Aachen Hbf | 60 vol.
- Köln Hbf | 65 vol.
- Düsseldorf Hbf | 20 vol.
- Dortmund Hbf | 40 vol.
- Osnabrück Hbf | 45 vol.
- Kiel Hbf | 30 vol.
LOAD: 270 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 60 vol.
- Würzburg Hbf | 25 vol.
- Nürnberg Hbf | 40 vol.
LOAD: 255 vol.
- München Hbf | 40 vol.
- Stuttgart Hbf | 85 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 65 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: 1110 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 20, 60, 20, 60, 85, 40, 90, 40, 35, 100, 40, 40, 65, 0, 65, 20, 30, 100, 25, 20, 45, 65] ITERATION Generation: #1 Best cost: 7141.849 | Path: [1, 0, 4, 8, 18, 10, 22, 2, 1, 7, 11, 13, 20, 6, 1, 9, 14, 17, 19, 3, 1, 5, 16, 12, 21, 23, 1] Best cost: 7067.077 | Path: [1, 2, 16, 5, 12, 22, 4, 10, 1, 7, 11, 0, 3, 17, 21, 1, 8, 18, 20, 6, 14, 1, 13, 9, 23, 19, 1] Best cost: 6991.737 | Path: [1, 3, 19, 17, 14, 21, 2, 1, 11, 7, 6, 20, 13, 1, 8, 18, 10, 22, 12, 5, 1, 4, 0, 16, 23, 9, 1] Best cost: 6755.877 | Path: [1, 4, 10, 22, 12, 2, 16, 5, 1, 11, 7, 13, 20, 3, 17, 1, 8, 18, 0, 19, 21, 1, 9, 6, 14, 23, 1] Best cost: 6740.525 | Path: [1, 9, 13, 20, 19, 3, 17, 1, 11, 7, 4, 10, 8, 1, 18, 22, 12, 2, 16, 5, 21, 1, 0, 14, 6, 23, 1] Best cost: 6573.552 | Path: [1, 13, 20, 3, 19, 17, 21, 2, 1, 7, 11, 0, 22, 12, 4, 1, 8, 18, 10, 16, 5, 1, 9, 6, 14, 23, 1] Best cost: 6339.764 | Path: [1, 13, 20, 17, 19, 3, 0, 1, 11, 7, 10, 8, 18, 1, 4, 22, 12, 2, 16, 5, 21, 1, 9, 6, 14, 23, 1] Best cost: 6247.806 | Path: [1, 7, 11, 4, 10, 8, 1, 18, 22, 12, 2, 16, 5, 21, 17, 1, 0, 3, 19, 20, 13, 1, 9, 6, 14, 23, 1] Generation: #7 Best cost: 6241.673 | Path: [1, 7, 11, 4, 10, 8, 1, 18, 22, 12, 2, 16, 5, 21, 17, 1, 0, 19, 3, 20, 13, 1, 9, 6, 14, 23, 1] OPTIMIZING each tour... Current: [[1, 7, 11, 4, 10, 8, 1], [1, 18, 22, 12, 2, 16, 5, 21, 17, 1], [1, 0, 19, 3, 20, 13, 1], [1, 9, 6, 14, 23, 1]] [2] Cost: 2003.885 to 1988.832 | Optimized: [1, 17, 21, 5, 16, 2, 12, 22, 18, 1] ACO RESULTS [1/285 vol./1098.074 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [2/300 vol./1988.832 km] Berlin Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Kiel Hbf --> Berlin Hbf [3/270 vol./1321.349 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf [4/255 vol./1818.365 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6226.620 km.