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 (45 vol.)
- Düsseldorf Hbf (100 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (95 vol.)
- Stuttgart Hbf (40 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (50 vol.)
- München Hbf (35 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (30 vol.)
- Ulm Hbf (50 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (50 vol.)
- Osnabrück Hbf (60 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1692.878 km
LOAD: 300 vol.
- Leipzig Hbf | 20 vol.
- Mainz Hbf | 100 vol.
- Mannheim Hbf | 70 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 80 vol.
Tour 2
COST: 1537.673 km
LOAD: 295 vol.
- München Hbf | 35 vol.
- Ulm Hbf | 50 vol.
- Stuttgart Hbf | 40 vol.
- Nürnberg Hbf | 75 vol.
- Dresden Hbf | 95 vol.
Tour 3
COST: 1113.837 km
LOAD: 300 vol.
- Hannover Hbf | 65 vol.
- Osnabrück Hbf | 60 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 25 vol.
Tour 4
COST: 1334.403 km
LOAD: 295 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 100 vol.
- Aachen Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 45 vol.
Tour 5
COST: 960.709 km
LOAD: 50 vol.
- Würzburg Hbf | 50 vol.
LOAD: 300 vol.
- Leipzig Hbf | 20 vol.
- Mainz Hbf | 100 vol.
- Mannheim Hbf | 70 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 80 vol.
LOAD: 295 vol.
- München Hbf | 35 vol.
- Ulm Hbf | 50 vol.
- Stuttgart Hbf | 40 vol.
- Nürnberg Hbf | 75 vol.
- Dresden Hbf | 95 vol.
LOAD: 300 vol.
- Hannover Hbf | 65 vol.
- Osnabrück Hbf | 60 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 25 vol.
LOAD: 295 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 100 vol.
- Aachen Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 45 vol.
LOAD: 50 vol.
- Würzburg Hbf | 50 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: 1240 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 100, 0, 65, 95, 40, 95, 50, 35, 100, 20, 55, 75, 30, 50, 0, 70, 25, 100, 50, 0, 60, 80] ITERATION Generation: #1 Best cost: 7873.353 | Path: [1, 0, 22, 10, 4, 11, 1, 7, 13, 20, 6, 14, 1, 8, 18, 12, 2, 17, 1, 5, 19, 23, 1, 15, 9, 1] Best cost: 7621.712 | Path: [1, 5, 2, 12, 0, 1, 11, 7, 20, 13, 9, 18, 1, 8, 10, 22, 4, 1, 19, 17, 14, 6, 15, 1, 23, 1] Best cost: 7514.553 | Path: [1, 8, 18, 10, 4, 22, 1, 11, 7, 15, 6, 14, 20, 1, 0, 12, 2, 5, 1, 9, 13, 17, 19, 1, 23, 1] Best cost: 7290.018 | Path: [1, 10, 8, 18, 4, 22, 1, 7, 11, 0, 12, 17, 1, 5, 2, 19, 1, 9, 15, 6, 14, 23, 20, 1, 13, 1] Best cost: 7032.498 | Path: [1, 12, 2, 5, 0, 1, 7, 11, 13, 20, 6, 1, 4, 10, 22, 8, 18, 1, 19, 17, 14, 23, 1, 9, 15, 1] Best cost: 6668.928 | Path: [1, 23, 14, 17, 19, 11, 1, 7, 6, 15, 9, 13, 1, 4, 22, 10, 8, 18, 1, 0, 12, 2, 5, 1, 20, 1] OPTIMIZING each tour... Current: [[1, 23, 14, 17, 19, 11, 1], [1, 7, 6, 15, 9, 13, 1], [1, 4, 22, 10, 8, 18, 1], [1, 0, 12, 2, 5, 1], [1, 20, 1]] [1] Cost: 1700.192 to 1692.878 | Optimized: [1, 11, 19, 17, 14, 23, 1] [2] Cost: 1558.277 to 1537.673 | Optimized: [1, 9, 15, 6, 13, 7, 1] [4] Cost: 1335.913 to 1334.403 | Optimized: [1, 12, 2, 5, 0, 1] ACO RESULTS [1/300 vol./1692.878 km] Berlin Hbf -> Leipzig Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [2/295 vol./1537.673 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/300 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/295 vol./1334.403 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [5/ 50 vol./ 960.709 km] Berlin Hbf -> Würzburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6639.500 km.