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: 19 customers
- Kassel-Wilhelmshöhe (70 vol.)
- Düsseldorf Hbf (100 vol.)
- Frankfurt Hbf (75 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (65 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (20 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (45 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (85 vol.)
- Mannheim Hbf (60 vol.)
- Kiel Hbf (20 vol.)
- Würzburg Hbf (20 vol.)
- Osnabrück Hbf (25 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1479.263 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 100 vol.
- Osnabrück Hbf | 25 vol.
- Bremen Hbf | 20 vol.
- Kiel Hbf | 20 vol.
Tour 2
COST: 1628.139 km
LOAD: 300 vol.
- Nürnberg Hbf | 45 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 30 vol.
- Würzburg Hbf | 20 vol.
- Leipzig Hbf | 80 vol.
- Dresden Hbf | 65 vol.
Tour 3
COST: 1286.411 km
LOAD: 250 vol.
- Aachen Hbf | 80 vol.
- Köln Hbf | 85 vol.
- Hannover Hbf | 85 vol.
Tour 4
COST: 1627.258 km
LOAD: 200 vol.
- Frankfurt Hbf | 75 vol.
- Mannheim Hbf | 60 vol.
- Freiburg Hbf | 65 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 100 vol.
- Osnabrück Hbf | 25 vol.
- Bremen Hbf | 20 vol.
- Kiel Hbf | 20 vol.
LOAD: 300 vol.
- Nürnberg Hbf | 45 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 30 vol.
- Würzburg Hbf | 20 vol.
- Leipzig Hbf | 80 vol.
- Dresden Hbf | 65 vol.
LOAD: 250 vol.
- Aachen Hbf | 80 vol.
- Köln Hbf | 85 vol.
- Hannover Hbf | 85 vol.
LOAD: 200 vol.
- Frankfurt Hbf | 75 vol.
- Mannheim Hbf | 60 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: 1050 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 100, 75, 85, 80, 30, 65, 0, 40, 20, 80, 65, 45, 0, 20, 85, 60, 20, 0, 20, 0, 25, 65] ITERATION Generation: #1 Best cost: 6922.600 | Path: [1, 0, 3, 17, 6, 15, 9, 1, 11, 7, 20, 13, 12, 22, 1, 18, 10, 4, 2, 23, 1, 16, 5, 1] Best cost: 6666.257 | Path: [1, 3, 17, 6, 15, 9, 13, 20, 1, 11, 7, 0, 12, 10, 1, 4, 22, 2, 16, 1, 18, 5, 23, 1] Best cost: 6604.479 | Path: [1, 4, 10, 22, 12, 2, 1, 7, 11, 0, 16, 1, 13, 20, 3, 17, 6, 15, 9, 1, 18, 5, 23, 1] Best cost: 6296.686 | Path: [1, 13, 20, 3, 17, 6, 15, 9, 1, 11, 7, 0, 4, 1, 18, 10, 22, 12, 2, 23, 1, 16, 5, 1] Best cost: 6294.780 | Path: [1, 9, 15, 6, 17, 3, 20, 13, 1, 11, 7, 0, 22, 10, 18, 1, 4, 12, 2, 1, 5, 16, 23, 1] Best cost: 6186.321 | Path: [1, 9, 15, 6, 17, 3, 20, 13, 1, 7, 11, 0, 22, 10, 18, 1, 4, 12, 2, 1, 16, 5, 23, 1] Best cost: 6178.521 | Path: [1, 0, 12, 2, 22, 10, 18, 1, 7, 11, 20, 13, 9, 15, 6, 1, 4, 16, 5, 1, 3, 17, 23, 1] Best cost: 6082.130 | Path: [1, 0, 12, 2, 22, 10, 18, 1, 7, 11, 13, 20, 6, 15, 9, 1, 4, 5, 16, 1, 3, 17, 23, 1] Generation: #2 Best cost: 6047.989 | Path: [1, 0, 12, 2, 22, 10, 18, 1, 11, 7, 13, 9, 15, 6, 20, 1, 4, 16, 5, 1, 3, 17, 23, 1] OPTIMIZING each tour... Current: [[1, 0, 12, 2, 22, 10, 18, 1], [1, 11, 7, 13, 9, 15, 6, 20, 1], [1, 4, 16, 5, 1], [1, 3, 17, 23, 1]] [2] Cost: 1652.972 to 1628.139 | Optimized: [1, 13, 9, 15, 6, 20, 11, 7, 1] [3] Cost: 1288.496 to 1286.411 | Optimized: [1, 5, 16, 4, 1] ACO RESULTS [1/300 vol./1479.263 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [2/300 vol./1628.139 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/250 vol./1286.411 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Hannover Hbf --> Berlin Hbf [4/200 vol./1627.258 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6021.071 km.