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 (95 vol.)
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (55 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (45 vol.)
- Bremen Hbf (90 vol.)
- Nürnberg Hbf (20 vol.)
- Karlsruhe Hbf (70 vol.)
- Ulm Hbf (50 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (30 vol.)
- Mainz Hbf (80 vol.)
- Würzburg Hbf (45 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (95 vol.)
Tour 1
COST: 1401.389 km
LOAD: 290 vol.
- Frankfurt Hbf | 45 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 70 vol.
- Stuttgart Hbf | 55 vol.
- Würzburg Hbf | 45 vol.
Tour 2
COST: 1166.325 km
LOAD: 290 vol.
- Dresden Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Osnabrück Hbf | 85 vol.
- Hannover Hbf | 40 vol.
Tour 3
COST: 1596.345 km
LOAD: 300 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 75 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 30 vol.
Tour 4
COST: 1874.166 km
LOAD: 290 vol.
- Nürnberg Hbf | 20 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 50 vol.
- Freiburg Hbf | 95 vol.
- Mainz Hbf | 80 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 45 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 70 vol.
- Stuttgart Hbf | 55 vol.
- Würzburg Hbf | 45 vol.
LOAD: 290 vol.
- Dresden Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Osnabrück Hbf | 85 vol.
- Hannover Hbf | 40 vol.
LOAD: 300 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 75 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 30 vol.
LOAD: 290 vol.
- Nürnberg Hbf | 20 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 50 vol.
- Freiburg Hbf | 95 vol.
- Mainz Hbf | 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: 1170 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 0, 45, 40, 75, 55, 70, 35, 45, 90, 0, 0, 20, 70, 50, 70, 75, 30, 80, 45, 0, 85, 95] ITERATION Generation: #1 Best cost: 7198.339 | Path: [1, 0, 3, 19, 17, 1, 7, 13, 20, 6, 14, 8, 1, 4, 10, 22, 16, 1, 18, 5, 15, 9, 23, 1] Best cost: 6877.766 | Path: [1, 5, 16, 22, 4, 18, 1, 7, 0, 19, 3, 1, 8, 10, 15, 6, 14, 1, 13, 20, 17, 23, 9, 1] Best cost: 6771.902 | Path: [1, 8, 18, 10, 4, 22, 13, 1, 7, 20, 6, 15, 14, 1, 0, 16, 5, 3, 1, 19, 17, 23, 9, 1] Best cost: 6718.085 | Path: [1, 17, 14, 6, 15, 9, 1, 7, 13, 20, 3, 19, 4, 1, 8, 10, 22, 16, 1, 18, 0, 5, 23, 1] Best cost: 6704.589 | Path: [1, 15, 6, 14, 17, 3, 1, 7, 13, 20, 19, 16, 1, 4, 10, 22, 5, 1, 18, 8, 0, 23, 9, 1] Best cost: 6244.544 | Path: [1, 23, 14, 6, 15, 13, 1, 7, 0, 22, 4, 1, 8, 18, 10, 16, 5, 1, 3, 19, 17, 20, 9, 1] Best cost: 6166.653 | Path: [1, 17, 14, 6, 15, 9, 1, 7, 0, 22, 4, 1, 8, 18, 10, 16, 5, 1, 13, 20, 3, 19, 23, 1] Best cost: 6147.940 | Path: [1, 9, 15, 6, 14, 17, 1, 7, 0, 22, 4, 1, 18, 8, 10, 16, 5, 1, 13, 20, 3, 19, 23, 1] Generation: #2 Best cost: 6116.500 | Path: [1, 20, 3, 19, 17, 6, 1, 7, 0, 22, 4, 1, 8, 18, 10, 16, 5, 1, 13, 9, 15, 14, 23, 1] Best cost: 6109.721 | Path: [1, 17, 14, 6, 15, 9, 1, 7, 0, 22, 4, 1, 8, 18, 10, 16, 5, 1, 20, 3, 19, 23, 13, 1] Generation: #4 Best cost: 6107.984 | Path: [1, 7, 0, 22, 4, 1, 20, 3, 19, 17, 6, 1, 8, 18, 10, 16, 5, 1, 9, 15, 14, 23, 13, 1] Generation: #5 Best cost: 6068.240 | Path: [1, 20, 6, 14, 17, 3, 1, 7, 0, 22, 4, 1, 8, 18, 10, 16, 5, 1, 13, 9, 15, 23, 19, 1] OPTIMIZING each tour... Current: [[1, 20, 6, 14, 17, 3, 1], [1, 7, 0, 22, 4, 1], [1, 8, 18, 10, 16, 5, 1], [1, 13, 9, 15, 23, 19, 1]] [1] Cost: 1410.810 to 1401.389 | Optimized: [1, 3, 17, 14, 6, 20, 1] [3] Cost: 1616.939 to 1596.345 | Optimized: [1, 16, 5, 10, 8, 18, 1] ACO RESULTS [1/290 vol./1401.389 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [2/290 vol./1166.325 km] Berlin Hbf -> Dresden Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [3/300 vol./1596.345 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/290 vol./1874.166 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf -> Mainz Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6038.225 km.