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: 19 customers
- Kassel-Wilhelmshöhe (80 vol.)
- Düsseldorf Hbf (60 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (30 vol.)
- Aachen Hbf (95 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (80 vol.)
- Bremen Hbf (70 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (35 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (45 vol.)
- Köln Hbf (80 vol.)
- Kiel Hbf (55 vol.)
- Mainz Hbf (60 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (85 vol.)
- Osnabrück Hbf (75 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1855.075 km
LOAD: 295 vol.
- Nürnberg Hbf | 35 vol.
- Ulm Hbf | 45 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 85 vol.
Tour 2
COST: 1300.94 km
LOAD: 275 vol.
- Mainz Hbf | 60 vol.
- Frankfurt Hbf | 80 vol.
- Würzburg Hbf | 60 vol.
- Dresden Hbf | 75 vol.
Tour 3
COST: 1262.806 km
LOAD: 290 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 60 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 70 vol.
- Hannover Hbf | 30 vol.
Tour 4
COST: 1342.718 km
LOAD: 255 vol.
- Kassel-Wilhelmshöhe | 80 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 80 vol.
Tour 5
COST: 732.557 km
LOAD: 135 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 55 vol.
LOAD: 295 vol.
- Nürnberg Hbf | 35 vol.
- Ulm Hbf | 45 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 85 vol.
LOAD: 275 vol.
- Mainz Hbf | 60 vol.
- Frankfurt Hbf | 80 vol.
- Würzburg Hbf | 60 vol.
- Dresden Hbf | 75 vol.
LOAD: 290 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 60 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 70 vol.
- Hannover Hbf | 30 vol.
LOAD: 255 vol.
- Kassel-Wilhelmshöhe | 80 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 80 vol.
LOAD: 135 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 55 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: 1250 vol. | Vehicle capacity: 300 vol. Loads: [80, 0, 60, 80, 30, 95, 0, 75, 80, 0, 70, 0, 55, 35, 55, 45, 80, 0, 55, 60, 60, 85, 75, 75] ITERATION Generation: #1 Best cost: 7603.070 | Path: [1, 0, 4, 22, 12, 2, 1, 7, 13, 20, 3, 15, 1, 8, 18, 10, 16, 1, 14, 23, 21, 19, 1, 5, 1] Best cost: 7316.378 | Path: [1, 2, 16, 5, 12, 1, 7, 13, 20, 3, 15, 1, 8, 18, 10, 22, 1, 4, 0, 19, 14, 23, 1, 21, 1] Best cost: 7055.175 | Path: [1, 14, 23, 21, 19, 1, 7, 13, 20, 3, 15, 1, 8, 18, 10, 22, 1, 4, 0, 12, 2, 1, 16, 5, 1] Best cost: 7035.381 | Path: [1, 16, 2, 5, 12, 1, 7, 20, 13, 15, 14, 4, 1, 8, 18, 10, 22, 1, 21, 19, 3, 23, 1, 0, 1] Best cost: 7021.752 | Path: [1, 14, 21, 19, 3, 1, 7, 13, 20, 0, 4, 1, 8, 18, 10, 22, 1, 2, 16, 5, 12, 1, 15, 23, 1] Best cost: 6964.066 | Path: [1, 18, 8, 10, 22, 1, 7, 4, 12, 2, 16, 1, 0, 3, 19, 20, 1, 13, 15, 14, 23, 21, 1, 5, 1] Best cost: 6833.590 | Path: [1, 23, 14, 19, 3, 4, 1, 7, 13, 20, 15, 21, 1, 8, 18, 10, 22, 1, 12, 2, 16, 5, 1, 0, 1] Best cost: 6772.268 | Path: [1, 12, 2, 16, 5, 1, 7, 20, 13, 15, 14, 4, 1, 8, 18, 10, 22, 1, 3, 19, 21, 23, 1, 0, 1] Generation: #3 Best cost: 6581.767 | Path: [1, 15, 14, 23, 21, 13, 1, 7, 20, 3, 19, 1, 4, 10, 22, 12, 2, 1, 0, 16, 5, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 15, 14, 23, 21, 13, 1], [1, 7, 20, 3, 19, 1], [1, 4, 10, 22, 12, 2, 1], [1, 0, 16, 5, 1], [1, 8, 18, 1]] [1] Cost: 1920.912 to 1855.075 | Optimized: [1, 13, 15, 14, 23, 21, 1] [2] Cost: 1303.754 to 1300.940 | Optimized: [1, 19, 3, 20, 7, 1] [3] Cost: 1281.284 to 1262.806 | Optimized: [1, 12, 2, 22, 10, 4, 1] [4] Cost: 1343.260 to 1342.718 | Optimized: [1, 0, 5, 16, 1] ACO RESULTS [1/295 vol./1855.075 km] Berlin Hbf -> Nürnberg Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [2/275 vol./1300.940 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Dresden Hbf --> Berlin Hbf [3/290 vol./1262.806 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf --> Berlin Hbf [4/255 vol./1342.718 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Aachen Hbf -> Köln Hbf --> Berlin Hbf [5/135 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6494.096 km.