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: 21 customers
- Kassel-Wilhelmshöhe (100 vol.)
- Düsseldorf Hbf (60 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (70 vol.)
- Dresden Hbf (100 vol.)
- Hamburg Hbf (85 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (45 vol.)
- Nürnberg Hbf (35 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (90 vol.)
- Köln Hbf (75 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (70 vol.)
- Saarbrücken Hbf (40 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1235.359 km
LOAD: 295 vol.
- Dresden Hbf | 100 vol.
- Leipzig Hbf | 50 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Dortmund Hbf | 45 vol.
Tour 2
COST: 1113.837 km
LOAD: 285 vol.
- Hannover Hbf | 25 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 50 vol.
Tour 3
COST: 1497.44 km
LOAD: 300 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 70 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 70 vol.
Tour 4
COST: 1888.859 km
LOAD: 290 vol.
- Nürnberg Hbf | 35 vol.
- Ulm Hbf | 90 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 40 vol.
- Mannheim Hbf | 20 vol.
Tour 5
COST: 960.709 km
LOAD: 70 vol.
- Würzburg Hbf | 70 vol.
LOAD: 295 vol.
- Dresden Hbf | 100 vol.
- Leipzig Hbf | 50 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Dortmund Hbf | 45 vol.
LOAD: 285 vol.
- Hannover Hbf | 25 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 50 vol.
LOAD: 300 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 70 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 70 vol.
LOAD: 290 vol.
- Nürnberg Hbf | 35 vol.
- Ulm Hbf | 90 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 40 vol.
- Mannheim Hbf | 20 vol.
LOAD: 70 vol.
- Würzburg Hbf | 70 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: [100, 0, 60, 70, 25, 70, 0, 100, 85, 0, 75, 50, 45, 35, 40, 90, 75, 20, 50, 25, 70, 40, 50, 65] ITERATION Generation: #1 Best cost: 7532.535 | Path: [1, 0, 12, 2, 16, 17, 1, 7, 11, 4, 10, 22, 1, 8, 18, 19, 3, 20, 1, 13, 15, 14, 23, 21, 1, 5, 1] Best cost: 7432.026 | Path: [1, 2, 16, 5, 12, 22, 1, 7, 11, 4, 10, 18, 1, 8, 0, 20, 13, 1, 21, 19, 3, 17, 14, 15, 1, 23, 1] Best cost: 7333.596 | Path: [1, 3, 19, 17, 14, 21, 23, 13, 1, 7, 11, 0, 22, 1, 8, 18, 4, 10, 12, 1, 5, 2, 16, 20, 1, 15, 1] Best cost: 7247.572 | Path: [1, 11, 7, 13, 20, 19, 17, 1, 8, 18, 10, 4, 22, 1, 0, 12, 2, 16, 1, 3, 14, 23, 21, 5, 1, 15, 1] Best cost: 7081.261 | Path: [1, 12, 2, 16, 5, 22, 1, 8, 18, 10, 4, 11, 1, 7, 20, 13, 19, 3, 1, 0, 17, 14, 23, 21, 1, 15, 1] Best cost: 6977.725 | Path: [1, 20, 13, 17, 14, 23, 21, 19, 1, 7, 11, 4, 8, 1, 18, 10, 22, 0, 1, 12, 2, 16, 5, 1, 3, 15, 1] Best cost: 6926.397 | Path: [1, 2, 16, 5, 12, 22, 1, 8, 18, 10, 4, 11, 1, 7, 13, 20, 3, 19, 1, 0, 17, 14, 23, 21, 1, 15, 1] Best cost: 6884.986 | Path: [1, 8, 18, 4, 22, 10, 1, 11, 7, 20, 3, 1, 12, 2, 16, 5, 19, 17, 1, 13, 15, 14, 23, 21, 1, 0, 1] Generation: #3 Best cost: 6854.017 | Path: [1, 7, 11, 0, 12, 1, 8, 18, 10, 22, 4, 1, 16, 2, 5, 19, 3, 1, 15, 14, 17, 21, 23, 13, 1, 20, 1] OPTIMIZING each tour... Current: [[1, 7, 11, 0, 12, 1], [1, 8, 18, 10, 22, 4, 1], [1, 16, 2, 5, 19, 3, 1], [1, 15, 14, 17, 21, 23, 13, 1], [1, 20, 1]] [2] Cost: 1136.947 to 1113.837 | Optimized: [1, 4, 22, 10, 8, 18, 1] [3] Cost: 1516.965 to 1497.440 | Optimized: [1, 2, 16, 5, 19, 3, 1] [4] Cost: 2004.037 to 1888.859 | Optimized: [1, 13, 15, 14, 23, 21, 17, 1] ACO RESULTS [1/295 vol./1235.359 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf --> Berlin Hbf [2/285 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/300 vol./1497.440 km] Berlin Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [4/290 vol./1888.859 km] Berlin Hbf -> Nürnberg Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mannheim Hbf --> Berlin Hbf [5/ 70 vol./ 960.709 km] Berlin Hbf -> Würzburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6696.204 km.