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 (35 vol.)
- Frankfurt Hbf (65 vol.)
- Hannover Hbf (30 vol.)
- Aachen Hbf (100 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (75 vol.)
- Bremen Hbf (25 vol.)
- Leipzig Hbf (95 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (30 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (30 vol.)
- Würzburg Hbf (100 vol.)
- Osnabrück Hbf (65 vol.)
- Freiburg Hbf (30 vol.)
Tour 1
COST: 1465.482 km
LOAD: 285 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 35 vol.
- Aachen Hbf | 100 vol.
- Mainz Hbf | 30 vol.
- Frankfurt Hbf | 65 vol.
Tour 2
COST: 1351.104 km
LOAD: 280 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 95 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 75 vol.
Tour 3
COST: 1113.837 km
LOAD: 295 vol.
- Hannover Hbf | 30 vol.
- Osnabrück Hbf | 65 vol.
- Bremen Hbf | 25 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 95 vol.
Tour 4
COST: 1708.268 km
LOAD: 260 vol.
- Würzburg Hbf | 100 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 30 vol.
- Ulm Hbf | 30 vol.
Tour 5
COST: 785.078 km
LOAD: 80 vol.
- Kassel-Wilhelmshöhe | 80 vol.
LOAD: 285 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 35 vol.
- Aachen Hbf | 100 vol.
- Mainz Hbf | 30 vol.
- Frankfurt Hbf | 65 vol.
LOAD: 280 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 95 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 75 vol.
LOAD: 295 vol.
- Hannover Hbf | 30 vol.
- Osnabrück Hbf | 65 vol.
- Bremen Hbf | 25 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 95 vol.
LOAD: 260 vol.
- Würzburg Hbf | 100 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 30 vol.
- Ulm Hbf | 30 vol.
LOAD: 80 vol.
- Kassel-Wilhelmshöhe | 80 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: 1200 vol. | Vehicle capacity: 300 vol. Loads: [80, 0, 35, 65, 30, 100, 0, 35, 80, 75, 25, 95, 55, 75, 100, 30, 0, 0, 95, 30, 100, 0, 65, 30] ITERATION Generation: #1 Best cost: 7350.376 | Path: [1, 0, 22, 10, 4, 8, 1, 11, 7, 13, 9, 1, 18, 12, 2, 5, 1, 20, 3, 19, 14, 1, 23, 15, 1] Best cost: 7114.093 | Path: [1, 3, 19, 14, 23, 15, 4, 1, 11, 7, 13, 9, 1, 8, 18, 10, 22, 2, 1, 0, 12, 5, 1, 20, 1] Best cost: 6987.058 | Path: [1, 8, 18, 10, 4, 22, 1, 11, 7, 13, 9, 1, 0, 2, 12, 5, 19, 1, 15, 14, 23, 3, 1, 20, 1] Best cost: 6938.516 | Path: [1, 9, 15, 14, 23, 3, 1, 11, 7, 13, 0, 1, 4, 10, 8, 18, 22, 1, 12, 2, 5, 19, 1, 20, 1] Best cost: 6602.438 | Path: [1, 3, 19, 14, 23, 13, 1, 11, 7, 0, 12, 2, 1, 8, 10, 4, 22, 5, 1, 18, 20, 15, 9, 1] Generation: #2 Best cost: 6535.586 | Path: [1, 12, 2, 5, 19, 3, 1, 11, 7, 13, 9, 1, 8, 18, 10, 22, 4, 1, 20, 15, 14, 23, 1, 0, 1] Generation: #3 Best cost: 6473.101 | Path: [1, 12, 2, 5, 19, 3, 1, 11, 7, 13, 9, 1, 8, 18, 10, 22, 4, 1, 20, 14, 23, 15, 1, 0, 1] OPTIMIZING each tour... Current: [[1, 12, 2, 5, 19, 3, 1], [1, 11, 7, 13, 9, 1], [1, 8, 18, 10, 22, 4, 1], [1, 20, 14, 23, 15, 1], [1, 0, 1]] [2] Cost: 1377.326 to 1351.104 | Optimized: [1, 7, 11, 13, 9, 1] [3] Cost: 1136.947 to 1113.837 | Optimized: [1, 4, 22, 10, 8, 18, 1] ACO RESULTS [1/285 vol./1465.482 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/280 vol./1351.104 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf [3/295 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/260 vol./1708.268 km] Berlin Hbf -> Würzburg Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Ulm Hbf --> Berlin Hbf [5/ 80 vol./ 785.078 km] Berlin Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6423.769 km.