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: 17 customers
- Kassel-Wilhelmshöhe (90 vol.)
- Düsseldorf Hbf (70 vol.)
- Frankfurt Hbf (85 vol.)
- Aachen Hbf (50 vol.)
- Dresden Hbf (80 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (20 vol.)
- Dortmund Hbf (60 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (90 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (40 vol.)
- Würzburg Hbf (55 vol.)
- Osnabrück Hbf (75 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1656.619 km
LOAD: 290 vol.
- Mainz Hbf | 40 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 20 vol.
- Würzburg Hbf | 55 vol.
Tour 2
COST: 1421.064 km
LOAD: 285 vol.
- Dresden Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 20 vol.
- Kiel Hbf | 20 vol.
Tour 3
COST: 1415.41 km
LOAD: 270 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 70 vol.
- Aachen Hbf | 50 vol.
- Hamburg Hbf | 90 vol.
Tour 4
COST: 1562.987 km
LOAD: 275 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 90 vol.
- Frankfurt Hbf | 85 vol.
LOAD: 290 vol.
- Mainz Hbf | 40 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 20 vol.
- Würzburg Hbf | 55 vol.
LOAD: 285 vol.
- Dresden Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 20 vol.
- Kiel Hbf | 20 vol.
LOAD: 270 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 70 vol.
- Aachen Hbf | 50 vol.
- Hamburg Hbf | 90 vol.
LOAD: 275 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 90 vol.
- Frankfurt Hbf | 85 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: 1120 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 70, 85, 0, 50, 0, 80, 90, 100, 20, 0, 60, 0, 100, 90, 0, 75, 20, 40, 55, 0, 75, 20] ITERATION Generation: #1 Best cost: 6781.905 | Path: [1, 0, 12, 2, 5, 10, 1, 7, 20, 3, 19, 23, 18, 1, 8, 22, 17, 1, 9, 15, 14, 1] Best cost: 6447.912 | Path: [1, 3, 19, 17, 14, 1, 7, 0, 12, 2, 1, 8, 18, 10, 22, 5, 23, 1, 20, 15, 9, 1] Best cost: 6225.650 | Path: [1, 5, 2, 12, 22, 10, 18, 1, 7, 9, 15, 23, 1, 8, 0, 3, 1, 20, 14, 17, 19, 1] Best cost: 6166.161 | Path: [1, 0, 22, 10, 8, 18, 1, 7, 20, 3, 19, 23, 1, 12, 2, 5, 17, 1, 9, 15, 14, 1] Best cost: 6129.594 | Path: [1, 23, 14, 17, 19, 20, 1, 7, 0, 22, 10, 18, 1, 8, 12, 2, 5, 1, 3, 15, 9, 1] Best cost: 6124.408 | Path: [1, 23, 14, 17, 19, 20, 1, 7, 0, 22, 10, 18, 1, 8, 12, 2, 5, 1, 9, 15, 3, 1] OPTIMIZING each tour... Current: [[1, 23, 14, 17, 19, 20, 1], [1, 7, 0, 22, 10, 18, 1], [1, 8, 12, 2, 5, 1], [1, 9, 15, 3, 1]] [1] Cost: 1722.758 to 1656.619 | Optimized: [1, 19, 17, 14, 23, 20, 1] [3] Cost: 1417.599 to 1415.410 | Optimized: [1, 12, 2, 5, 8, 1] ACO RESULTS [1/290 vol./1656.619 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [2/285 vol./1421.064 km] Berlin Hbf -> Dresden Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [3/270 vol./1415.410 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Hamburg Hbf --> Berlin Hbf [4/275 vol./1562.987 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Frankfurt Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6056.080 km.