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 (45 vol.)
- Düsseldorf Hbf (60 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (75 vol.)
- Stuttgart Hbf (85 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (35 vol.)
- Bremen Hbf (85 vol.)
- Leipzig Hbf (85 vol.)
- Nürnberg Hbf (80 vol.)
- Ulm Hbf (55 vol.)
- Mannheim Hbf (80 vol.)
- Kiel Hbf (35 vol.)
- Würzburg Hbf (70 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (55 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1537.673 km
LOAD: 290 vol.
- München Hbf | 35 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 85 vol.
- Nürnberg Hbf | 80 vol.
- Dresden Hbf | 35 vol.
Tour 2
COST: 1321.024 km
LOAD: 290 vol.
- Frankfurt Hbf | 55 vol.
- Mannheim Hbf | 80 vol.
- Würzburg Hbf | 70 vol.
- Leipzig Hbf | 85 vol.
Tour 3
COST: 1113.837 km
LOAD: 285 vol.
- Hannover Hbf | 75 vol.
- Osnabrück Hbf | 55 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 35 vol.
Tour 4
COST: 1895.396 km
LOAD: 295 vol.
- Düsseldorf Hbf | 60 vol.
- Saarbrücken Hbf | 100 vol.
- Freiburg Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 45 vol.
LOAD: 290 vol.
- München Hbf | 35 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 85 vol.
- Nürnberg Hbf | 80 vol.
- Dresden Hbf | 35 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 55 vol.
- Mannheim Hbf | 80 vol.
- Würzburg Hbf | 70 vol.
- Leipzig Hbf | 85 vol.
LOAD: 285 vol.
- Hannover Hbf | 75 vol.
- Osnabrück Hbf | 55 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 35 vol.
LOAD: 295 vol.
- Düsseldorf Hbf | 60 vol.
- Saarbrücken Hbf | 100 vol.
- Freiburg Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 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: 1160 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 60, 55, 75, 0, 85, 35, 35, 35, 85, 85, 0, 80, 0, 55, 0, 80, 35, 0, 70, 100, 55, 90] ITERATION Generation: #1 Best cost: 7346.785 | Path: [1, 0, 22, 4, 10, 8, 1, 7, 11, 13, 20, 1, 17, 3, 6, 15, 1, 18, 2, 21, 23, 1, 9, 1] Best cost: 6410.826 | Path: [1, 3, 17, 21, 2, 1, 7, 11, 4, 10, 1, 8, 18, 22, 0, 20, 15, 1, 13, 9, 6, 23, 1] Best cost: 6351.450 | Path: [1, 23, 17, 3, 20, 1, 11, 7, 4, 10, 1, 13, 9, 15, 6, 0, 1, 8, 18, 22, 2, 21, 1] Best cost: 6135.178 | Path: [1, 9, 15, 6, 20, 3, 1, 11, 7, 13, 17, 1, 4, 22, 10, 8, 18, 1, 0, 2, 21, 23, 1] Best cost: 6132.631 | Path: [1, 18, 8, 10, 22, 4, 1, 7, 11, 0, 20, 3, 1, 15, 6, 17, 13, 1, 9, 23, 21, 2, 1] Best cost: 6104.158 | Path: [1, 18, 8, 10, 22, 4, 1, 11, 7, 3, 17, 0, 1, 13, 20, 6, 15, 1, 2, 21, 23, 9, 1] Best cost: 6049.187 | Path: [1, 18, 8, 10, 22, 4, 1, 7, 11, 0, 3, 17, 1, 13, 20, 6, 15, 1, 9, 23, 21, 2, 1] Best cost: 5928.904 | Path: [1, 6, 15, 9, 13, 7, 1, 11, 20, 3, 17, 1, 18, 8, 10, 22, 4, 1, 0, 2, 21, 23, 1] OPTIMIZING each tour... Current: [[1, 6, 15, 9, 13, 7, 1], [1, 11, 20, 3, 17, 1], [1, 18, 8, 10, 22, 4, 1], [1, 0, 2, 21, 23, 1]] [1] Cost: 1558.345 to 1537.673 | Optimized: [1, 9, 15, 6, 13, 7, 1] [2] Cost: 1338.838 to 1321.024 | Optimized: [1, 3, 17, 20, 11, 1] [3] Cost: 1126.118 to 1113.837 | Optimized: [1, 4, 22, 10, 8, 18, 1] [4] Cost: 1905.603 to 1895.396 | Optimized: [1, 2, 21, 23, 0, 1] ACO RESULTS [1/290 vol./1537.673 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [2/290 vol./1321.024 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Würzburg Hbf -> Leipzig Hbf --> Berlin Hbf [3/285 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/295 vol./1895.396 km] Berlin Hbf -> Düsseldorf Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5867.930 km.