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: 15 customers
- Kassel-Wilhelmshöhe (35 vol.)
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (90 vol.)
- Dresden Hbf (55 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (55 vol.)
- Dortmund Hbf (25 vol.)
- Nürnberg Hbf (20 vol.)
- Köln Hbf (30 vol.)
- Kiel Hbf (35 vol.)
- Würzburg Hbf (45 vol.)
- Osnabrück Hbf (65 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1662.495 km
LOAD: 290 vol.
- Dresden Hbf | 55 vol.
- Nürnberg Hbf | 20 vol.
- Würzburg Hbf | 45 vol.
- Frankfurt Hbf | 45 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 70 vol.
- Dortmund Hbf | 25 vol.
Tour 2
COST: 1315.124 km
LOAD: 290 vol.
- Hannover Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Osnabrück Hbf | 65 vol.
- Bremen Hbf | 55 vol.
- Kiel Hbf | 35 vol.
Tour 3
COST: 1810.917 km
LOAD: 205 vol.
- München Hbf | 95 vol.
- Stuttgart Hbf | 90 vol.
- Freiburg Hbf | 20 vol.
LOAD: 290 vol.
- Dresden Hbf | 55 vol.
- Nürnberg Hbf | 20 vol.
- Würzburg Hbf | 45 vol.
- Frankfurt Hbf | 45 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 70 vol.
- Dortmund Hbf | 25 vol.
LOAD: 290 vol.
- Hannover Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Osnabrück Hbf | 65 vol.
- Bremen Hbf | 55 vol.
- Kiel Hbf | 35 vol.
LOAD: 205 vol.
- München Hbf | 95 vol.
- Stuttgart Hbf | 90 vol.
- Freiburg Hbf | 20 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: 785 vol. | Vehicle capacity: 300 vol. Loads: [35, 0, 0, 45, 100, 70, 90, 55, 0, 95, 55, 0, 25, 20, 0, 0, 30, 0, 35, 0, 45, 0, 65, 20] ITERATION Generation: #1 Best cost: 5811.135 | Path: [1, 0, 3, 20, 13, 9, 23, 16, 1, 7, 4, 10, 22, 12, 1, 18, 5, 6, 1] Best cost: 5611.052 | Path: [1, 4, 22, 10, 18, 12, 23, 1, 7, 13, 20, 3, 16, 5, 0, 1, 9, 6, 1] Best cost: 5002.150 | Path: [1, 12, 16, 5, 3, 20, 13, 7, 1, 4, 10, 18, 22, 0, 1, 6, 23, 9, 1] Best cost: 4870.067 | Path: [1, 18, 10, 22, 4, 0, 1, 7, 13, 20, 3, 16, 5, 12, 1, 9, 6, 23, 1] Best cost: 4866.196 | Path: [1, 0, 4, 22, 10, 18, 1, 7, 13, 20, 3, 16, 5, 12, 1, 9, 6, 23, 1] Best cost: 4813.892 | Path: [1, 0, 22, 4, 10, 18, 1, 7, 13, 9, 6, 23, 1, 12, 16, 5, 3, 20, 1] Generation: #3 Best cost: 4798.315 | Path: [1, 12, 16, 5, 3, 20, 13, 7, 1, 18, 10, 22, 0, 4, 1, 9, 6, 23, 1] Generation: #6 Best cost: 4796.478 | Path: [1, 7, 13, 20, 3, 16, 5, 12, 1, 18, 10, 22, 0, 4, 1, 9, 6, 23, 1] Generation: #8 Best cost: 4791.420 | Path: [1, 7, 13, 9, 6, 23, 1, 18, 10, 22, 12, 16, 5, 1, 4, 0, 3, 20, 1] Best cost: 4788.536 | Path: [1, 7, 13, 20, 3, 16, 5, 12, 1, 4, 0, 22, 10, 18, 1, 9, 6, 23, 1] OPTIMIZING each tour... Current: [[1, 7, 13, 20, 3, 16, 5, 12, 1], [1, 4, 0, 22, 10, 18, 1], [1, 9, 6, 23, 1]] No changes made. ACO RESULTS [1/290 vol./1662.495 km] Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Köln Hbf -> Aachen Hbf -> Dortmund Hbf --> Berlin Hbf [2/290 vol./1315.124 km] Berlin Hbf -> Hannover Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [3/205 vol./1810.917 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4788.536 km.