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: 20 customers
- Kassel-Wilhelmshöhe (90 vol.)
- Düsseldorf Hbf (70 vol.)
- Frankfurt Hbf (80 vol.)
- Aachen Hbf (70 vol.)
- Dresden Hbf (100 vol.)
- Hamburg Hbf (70 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (75 vol.)
- Dortmund Hbf (75 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (60 vol.)
- Ulm Hbf (60 vol.)
- Mannheim Hbf (55 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (45 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (45 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1490.595 km
LOAD: 300 vol.
- Mannheim Hbf | 55 vol.
- Saarbrücken Hbf | 70 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 80 vol.
Tour 2
COST: 1187.501 km
LOAD: 300 vol.
- Würzburg Hbf | 45 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 75 vol.
- Dresden Hbf | 100 vol.
Tour 3
COST: 1136.992 km
LOAD: 290 vol.
- Dortmund Hbf | 75 vol.
- Osnabrück Hbf | 45 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 70 vol.
Tour 4
COST: 1613.33 km
LOAD: 300 vol.
- Kiel Hbf | 70 vol.
- Düsseldorf Hbf | 70 vol.
- Aachen Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 90 vol.
Tour 5
COST: 1819.169 km
LOAD: 295 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 60 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 75 vol.
LOAD: 300 vol.
- Mannheim Hbf | 55 vol.
- Saarbrücken Hbf | 70 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 80 vol.
LOAD: 300 vol.
- Würzburg Hbf | 45 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 75 vol.
- Dresden Hbf | 100 vol.
LOAD: 290 vol.
- Dortmund Hbf | 75 vol.
- Osnabrück Hbf | 45 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 70 vol.
LOAD: 300 vol.
- Kiel Hbf | 70 vol.
- Düsseldorf Hbf | 70 vol.
- Aachen Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 90 vol.
LOAD: 295 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 60 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 75 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: 1485 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 70, 80, 0, 70, 0, 100, 70, 100, 100, 75, 75, 80, 60, 60, 0, 55, 70, 95, 45, 70, 45, 75] ITERATION Generation: #1 Best cost: 8924.250 | Path: [1, 0, 12, 2, 22, 1, 11, 7, 13, 20, 1, 18, 8, 10, 17, 1, 5, 3, 19, 1, 9, 15, 14, 23, 1, 21, 1] Best cost: 8824.264 | Path: [1, 2, 12, 22, 10, 1, 7, 11, 0, 1, 8, 18, 13, 20, 1, 14, 17, 3, 19, 1, 9, 15, 23, 1, 5, 21, 1] Best cost: 8552.924 | Path: [1, 3, 19, 17, 14, 1, 11, 7, 13, 20, 1, 18, 8, 10, 22, 1, 0, 12, 2, 15, 1, 5, 21, 23, 1, 9, 1] Best cost: 8185.692 | Path: [1, 7, 11, 0, 1, 18, 8, 10, 22, 1, 12, 2, 5, 21, 1, 13, 20, 3, 19, 1, 9, 15, 14, 17, 1, 23, 1] Best cost: 7908.505 | Path: [1, 8, 18, 10, 22, 1, 7, 11, 0, 1, 13, 20, 3, 19, 1, 12, 2, 5, 21, 1, 17, 14, 23, 15, 1, 9, 1] Best cost: 7411.085 | Path: [1, 21, 19, 3, 17, 1, 11, 7, 13, 20, 1, 8, 10, 22, 12, 1, 18, 2, 5, 0, 1, 9, 15, 14, 23, 1] OPTIMIZING each tour... Current: [[1, 21, 19, 3, 17, 1], [1, 11, 7, 13, 20, 1], [1, 8, 10, 22, 12, 1], [1, 18, 2, 5, 0, 1], [1, 9, 15, 14, 23, 1]] [1] Cost: 1613.360 to 1490.595 | Optimized: [1, 17, 21, 19, 3, 1] [2] Cost: 1216.319 to 1187.501 | Optimized: [1, 20, 13, 11, 7, 1] [3] Cost: 1148.907 to 1136.992 | Optimized: [1, 12, 22, 10, 8, 1] ACO RESULTS [1/300 vol./1490.595 km] Berlin Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/300 vol./1187.501 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/290 vol./1136.992 km] Berlin Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [4/300 vol./1613.330 km] Berlin Hbf -> Kiel Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [5/295 vol./1819.169 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7247.587 km.