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: 18 customers
- Kassel-Wilhelmshöhe (40 vol.)
- Düsseldorf Hbf (50 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (55 vol.)
- Dresden Hbf (25 vol.)
- München Hbf (65 vol.)
- Leipzig Hbf (30 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (60 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (30 vol.)
- Mainz Hbf (25 vol.)
- Saarbrücken Hbf (95 vol.)
- Osnabrück Hbf (75 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1638.838 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Mainz Hbf | 25 vol.
- Mannheim Hbf | 30 vol.
- Karlsruhe Hbf | 95 vol.
- Stuttgart Hbf | 55 vol.
- Leipzig Hbf | 30 vol.
- Dresden Hbf | 25 vol.
Tour 2
COST: 1225.434 km
LOAD: 290 vol.
- Hannover Hbf | 40 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 70 vol.
- Osnabrück Hbf | 75 vol.
Tour 3
COST: 2001.75 km
LOAD: 300 vol.
- Ulm Hbf | 60 vol.
- Freiburg Hbf | 70 vol.
- Saarbrücken Hbf | 95 vol.
- Aachen Hbf | 75 vol.
Tour 4
COST: 1189.939 km
LOAD: 125 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 65 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Mainz Hbf | 25 vol.
- Mannheim Hbf | 30 vol.
- Karlsruhe Hbf | 95 vol.
- Stuttgart Hbf | 55 vol.
- Leipzig Hbf | 30 vol.
- Dresden Hbf | 25 vol.
LOAD: 290 vol.
- Hannover Hbf | 40 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 70 vol.
- Osnabrück Hbf | 75 vol.
LOAD: 300 vol.
- Ulm Hbf | 60 vol.
- Freiburg Hbf | 70 vol.
- Saarbrücken Hbf | 95 vol.
- Aachen Hbf | 75 vol.
LOAD: 125 vol.
- Nürnberg Hbf | 60 vol.
- München 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: 1015 vol. | Vehicle capacity: 300 vol. Loads: [40, 0, 50, 0, 40, 75, 55, 25, 0, 65, 0, 30, 55, 60, 95, 60, 70, 30, 0, 25, 0, 95, 75, 70] ITERATION Generation: #1 Best cost: 6639.643 | Path: [1, 0, 22, 12, 2, 16, 1, 7, 11, 4, 5, 21, 17, 1, 13, 15, 6, 14, 19, 1, 9, 23, 1] Best cost: 6366.844 | Path: [1, 2, 16, 5, 12, 0, 1, 7, 11, 13, 9, 15, 6, 1, 4, 22, 19, 17, 14, 1, 21, 23, 1] Best cost: 6301.197 | Path: [1, 5, 16, 2, 12, 0, 1, 7, 11, 19, 17, 14, 6, 4, 1, 22, 21, 23, 15, 1, 13, 9, 1] Best cost: 6297.422 | Path: [1, 19, 17, 14, 6, 15, 11, 1, 7, 4, 22, 12, 2, 0, 1, 13, 9, 23, 21, 1, 16, 5, 1] Best cost: 6271.672 | Path: [1, 9, 15, 6, 14, 19, 1, 7, 11, 0, 22, 12, 2, 1, 4, 17, 21, 23, 13, 1, 16, 5, 1] Best cost: 6206.822 | Path: [1, 4, 22, 12, 2, 16, 1, 11, 7, 13, 9, 15, 6, 1, 0, 19, 17, 14, 23, 1, 5, 21, 1] Best cost: 6197.602 | Path: [1, 16, 2, 12, 22, 4, 1, 11, 7, 13, 9, 15, 6, 1, 0, 19, 17, 14, 23, 1, 21, 5, 1] Best cost: 6191.507 | Path: [1, 15, 6, 14, 17, 19, 11, 1, 7, 21, 23, 16, 0, 1, 22, 12, 2, 5, 4, 1, 13, 9, 1] Best cost: 6175.340 | Path: [1, 16, 2, 12, 22, 4, 1, 7, 11, 13, 9, 15, 6, 1, 0, 19, 17, 14, 23, 1, 5, 21, 1] Generation: #2 Best cost: 6131.149 | Path: [1, 21, 23, 14, 17, 1, 11, 7, 13, 9, 15, 6, 1, 4, 22, 12, 2, 16, 1, 0, 19, 5, 1] Generation: #9 Best cost: 6095.222 | Path: [1, 7, 11, 0, 19, 17, 14, 6, 1, 4, 22, 12, 2, 16, 1, 5, 21, 23, 15, 1, 13, 9, 1] OPTIMIZING each tour... Current: [[1, 7, 11, 0, 19, 17, 14, 6, 1], [1, 4, 22, 12, 2, 16, 1], [1, 5, 21, 23, 15, 1], [1, 13, 9, 1]] [1] Cost: 1666.761 to 1638.838 | Optimized: [1, 0, 19, 17, 14, 6, 11, 7, 1] [2] Cost: 1232.263 to 1225.434 | Optimized: [1, 4, 12, 2, 16, 22, 1] [3] Cost: 2006.259 to 2001.750 | Optimized: [1, 15, 23, 21, 5, 1] ACO RESULTS [1/300 vol./1638.838 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [2/290 vol./1225.434 km] Berlin Hbf -> Hannover Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Osnabrück Hbf --> Berlin Hbf [3/300 vol./2001.750 km] Berlin Hbf -> Ulm Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf --> Berlin Hbf [4/125 vol./1189.939 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6055.961 km.