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: 15 customers
- Kassel-Wilhelmshöhe (20 vol.)
- Hannover Hbf (90 vol.)
- Aachen Hbf (35 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (85 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (45 vol.)
- Nürnberg Hbf (30 vol.)
- Ulm Hbf (75 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (85 vol.)
- Würzburg Hbf (100 vol.)
- Saarbrücken Hbf (85 vol.)
- Freiburg Hbf (30 vol.)
Tour 1
COST: 1765.614 km
LOAD: 300 vol.
- Mannheim Hbf | 85 vol.
- Saarbrücken Hbf | 85 vol.
- Freiburg Hbf | 30 vol.
- Würzburg Hbf | 100 vol.
Tour 2
COST: 1197.302 km
LOAD: 300 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Hannover Hbf | 90 vol.
- Hamburg Hbf | 85 vol.
Tour 3
COST: 1912.769 km
LOAD: 300 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 75 vol.
- Aachen Hbf | 35 vol.
- Köln Hbf | 30 vol.
- Dortmund Hbf | 45 vol.
LOAD: 300 vol.
- Mannheim Hbf | 85 vol.
- Saarbrücken Hbf | 85 vol.
- Freiburg Hbf | 30 vol.
- Würzburg Hbf | 100 vol.
LOAD: 300 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Hannover Hbf | 90 vol.
- Hamburg Hbf | 85 vol.
LOAD: 300 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 75 vol.
- Aachen Hbf | 35 vol.
- Köln Hbf | 30 vol.
- Dortmund Hbf | 45 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: 900 vol. | Vehicle capacity: 300 vol. Loads: [20, 0, 0, 0, 90, 35, 0, 25, 85, 85, 0, 80, 45, 30, 0, 75, 30, 85, 0, 0, 100, 85, 0, 30] ITERATION Generation: #1 Best cost: 5943.649 | Path: [1, 0, 12, 16, 5, 21, 17, 1, 11, 7, 4, 8, 1, 13, 20, 15, 9, 1, 23, 1] Best cost: 5464.725 | Path: [1, 13, 20, 17, 21, 1, 11, 7, 4, 8, 0, 1, 15, 9, 23, 16, 5, 12, 1] Best cost: 5304.455 | Path: [1, 12, 16, 5, 0, 4, 11, 1, 7, 13, 9, 15, 17, 1, 8, 20, 23, 21, 1] Best cost: 5192.982 | Path: [1, 13, 20, 17, 21, 1, 7, 11, 4, 8, 0, 1, 12, 16, 5, 23, 15, 9, 1] Best cost: 5033.631 | Path: [1, 17, 21, 23, 15, 7, 1, 11, 0, 12, 16, 5, 4, 1, 8, 20, 13, 9, 1] Generation: #5 Best cost: 5013.282 | Path: [1, 23, 21, 17, 20, 1, 11, 7, 0, 4, 8, 1, 13, 9, 15, 5, 16, 12, 1] OPTIMIZING each tour... Current: [[1, 23, 21, 17, 20, 1], [1, 11, 7, 0, 4, 8, 1], [1, 13, 9, 15, 5, 16, 12, 1]] [1] Cost: 1808.199 to 1765.614 | Optimized: [1, 17, 21, 23, 20, 1] [2] Cost: 1292.314 to 1197.302 | Optimized: [1, 7, 11, 0, 4, 8, 1] ACO RESULTS [1/300 vol./1765.614 km] Berlin Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [2/300 vol./1197.302 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf [3/300 vol./1912.769 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Aachen Hbf -> Köln Hbf -> Dortmund Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4875.685 km.