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 (50 vol.)
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (60 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (25 vol.)
- München Hbf (25 vol.)
- Leipzig Hbf (90 vol.)
- Köln Hbf (85 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (25 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (45 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1975.734 km
LOAD: 295 vol.
- Frankfurt Hbf | 70 vol.
- Mannheim Hbf | 70 vol.
- Saarbrücken Hbf | 45 vol.
- Freiburg Hbf | 85 vol.
- München Hbf | 25 vol.
Tour 2
COST: 1197.302 km
LOAD: 300 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Hannover Hbf | 60 vol.
- Hamburg Hbf | 25 vol.
Tour 3
COST: 1419.777 km
LOAD: 285 vol.
- Osnabrück Hbf | 85 vol.
- Düsseldorf Hbf | 35 vol.
- Köln Hbf | 85 vol.
- Würzburg Hbf | 80 vol.
Tour 4
COST: 701.943 km
LOAD: 25 vol.
- Kiel Hbf | 25 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 70 vol.
- Mannheim Hbf | 70 vol.
- Saarbrücken Hbf | 45 vol.
- Freiburg Hbf | 85 vol.
- München Hbf | 25 vol.
LOAD: 300 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Hannover Hbf | 60 vol.
- Hamburg Hbf | 25 vol.
LOAD: 285 vol.
- Osnabrück Hbf | 85 vol.
- Düsseldorf Hbf | 35 vol.
- Köln Hbf | 85 vol.
- Würzburg Hbf | 80 vol.
LOAD: 25 vol.
- Kiel 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: 905 vol. | Vehicle capacity: 300 vol. Loads: [50, 0, 35, 70, 60, 0, 0, 75, 25, 25, 0, 90, 0, 0, 0, 0, 85, 70, 25, 0, 80, 45, 85, 85] ITERATION Generation: #1 Best cost: 6788.534 | Path: [1, 0, 3, 17, 21, 2, 8, 1, 11, 7, 20, 9, 18, 1, 4, 22, 16, 1, 23, 1] Best cost: 6600.425 | Path: [1, 2, 16, 22, 4, 8, 1, 7, 11, 0, 3, 1, 18, 20, 17, 21, 9, 1, 23, 1] Best cost: 6431.211 | Path: [1, 8, 18, 4, 22, 0, 2, 1, 7, 11, 20, 9, 1, 3, 17, 21, 16, 1, 23, 1] Best cost: 6232.960 | Path: [1, 9, 20, 3, 17, 21, 1, 11, 7, 4, 8, 18, 1, 22, 0, 2, 16, 1, 23, 1] Best cost: 5955.352 | Path: [1, 16, 2, 22, 4, 8, 1, 7, 11, 20, 0, 1, 18, 3, 17, 21, 23, 1, 9, 1] Best cost: 5888.634 | Path: [1, 7, 11, 0, 22, 1, 8, 18, 4, 16, 2, 3, 1, 20, 17, 21, 23, 1, 9, 1] Best cost: 5416.845 | Path: [1, 16, 2, 22, 4, 8, 1, 7, 11, 20, 0, 1, 17, 3, 21, 23, 9, 1, 18, 1] Best cost: 5294.756 | Path: [1, 3, 17, 21, 23, 9, 1, 7, 11, 0, 4, 8, 1, 22, 2, 16, 20, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 3, 17, 21, 23, 9, 1], [1, 7, 11, 0, 4, 8, 1], [1, 22, 2, 16, 20, 1], [1, 18, 1]] No changes made. ACO RESULTS [1/295 vol./1975.734 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> München 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/285 vol./1419.777 km] Berlin Hbf -> Osnabrück Hbf -> Düsseldorf Hbf -> Köln Hbf -> Würzburg Hbf --> Berlin Hbf [4/ 25 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5294.756 km.