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: 14 customers
- Kassel-Wilhelmshöhe (65 vol.)
- Düsseldorf Hbf (70 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (40 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (85 vol.)
- Leipzig Hbf (60 vol.)
- Dortmund Hbf (25 vol.)
- Karlsruhe Hbf (50 vol.)
- Ulm Hbf (20 vol.)
- Mannheim Hbf (50 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (40 vol.)
Tour 1
COST: 1796.568 km
LOAD: 295 vol.
- Saarbrücken Hbf | 40 vol.
- Mannheim Hbf | 50 vol.
- Karlsruhe Hbf | 50 vol.
- Stuttgart Hbf | 95 vol.
- Ulm Hbf | 20 vol.
- Dresden Hbf | 40 vol.
Tour 2
COST: 1506.389 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Würzburg Hbf | 90 vol.
- München Hbf | 85 vol.
- Leipzig Hbf | 60 vol.
Tour 3
COST: 1411.448 km
LOAD: 260 vol.
- Hamburg Hbf | 65 vol.
- Düsseldorf Hbf | 70 vol.
- Aachen Hbf | 100 vol.
- Dortmund Hbf | 25 vol.
LOAD: 295 vol.
- Saarbrücken Hbf | 40 vol.
- Mannheim Hbf | 50 vol.
- Karlsruhe Hbf | 50 vol.
- Stuttgart Hbf | 95 vol.
- Ulm Hbf | 20 vol.
- Dresden Hbf | 40 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Würzburg Hbf | 90 vol.
- München Hbf | 85 vol.
- Leipzig Hbf | 60 vol.
LOAD: 260 vol.
- Hamburg Hbf | 65 vol.
- Düsseldorf Hbf | 70 vol.
- Aachen Hbf | 100 vol.
- Dortmund Hbf | 25 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: 855 vol. | Vehicle capacity: 300 vol. Loads: [65, 0, 70, 0, 0, 100, 95, 40, 65, 85, 0, 60, 25, 0, 50, 20, 0, 50, 0, 0, 90, 40, 0, 0] ITERATION Generation: #1 Best cost: 5008.187 | Path: [1, 0, 12, 2, 5, 21, 1, 7, 11, 20, 15, 9, 1, 8, 14, 17, 6, 1] Best cost: 4884.091 | Path: [1, 8, 0, 5, 2, 1, 7, 11, 20, 6, 1, 12, 21, 17, 14, 15, 9, 1] Best cost: 4848.365 | Path: [1, 8, 12, 2, 5, 21, 1, 11, 7, 20, 6, 1, 0, 17, 14, 15, 9, 1] Best cost: 4814.652 | Path: [1, 21, 14, 17, 6, 15, 7, 1, 11, 0, 20, 9, 1, 8, 5, 2, 12, 1] Best cost: 4812.503 | Path: [1, 7, 11, 20, 6, 1, 8, 12, 2, 5, 21, 1, 0, 17, 14, 15, 9, 1] Best cost: 4749.807 | Path: [1, 21, 17, 14, 6, 15, 7, 1, 11, 0, 20, 9, 1, 8, 12, 2, 5, 1] Generation: #5 Best cost: 4743.656 | Path: [1, 21, 17, 14, 6, 15, 7, 1, 11, 0, 20, 9, 1, 8, 2, 5, 12, 1] OPTIMIZING each tour... Current: [[1, 21, 17, 14, 6, 15, 7, 1], [1, 11, 0, 20, 9, 1], [1, 8, 2, 5, 12, 1]] [2] Cost: 1535.640 to 1506.389 | Optimized: [1, 0, 20, 9, 11, 1] ACO RESULTS [1/295 vol./1796.568 km] Berlin Hbf -> Saarbrücken Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf -> Dresden Hbf --> Berlin Hbf [2/300 vol./1506.389 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Würzburg Hbf -> München Hbf -> Leipzig Hbf --> Berlin Hbf [3/260 vol./1411.448 km] Berlin Hbf -> Hamburg Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Dortmund Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4714.405 km.