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 (70 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (60 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (85 vol.)
- Dresden Hbf (50 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (85 vol.)
- Dortmund Hbf (70 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (40 vol.)
- Köln Hbf (20 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (80 vol.)
Tour 1
COST: 1748.101 km
LOAD: 290 vol.
- Düsseldorf Hbf | 90 vol.
- Köln Hbf | 20 vol.
- Aachen Hbf | 60 vol.
- Saarbrücken Hbf | 80 vol.
- Karlsruhe Hbf | 40 vol.
Tour 2
COST: 1354.595 km
LOAD: 300 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 80 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 60 vol.
- Dresden Hbf | 50 vol.
Tour 3
COST: 959.498 km
LOAD: 245 vol.
- Hamburg Hbf | 80 vol.
- Bremen Hbf | 85 vol.
- Kiel Hbf | 80 vol.
Tour 4
COST: 1099.924 km
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Dortmund Hbf | 70 vol.
- Osnabrück Hbf | 80 vol.
- Hannover Hbf | 60 vol.
Tour 5
COST: 1430.64 km
LOAD: 185 vol.
- München Hbf | 100 vol.
- Stuttgart Hbf | 85 vol.
LOAD: 290 vol.
- Düsseldorf Hbf | 90 vol.
- Köln Hbf | 20 vol.
- Aachen Hbf | 60 vol.
- Saarbrücken Hbf | 80 vol.
- Karlsruhe Hbf | 40 vol.
LOAD: 300 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 80 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 60 vol.
- Dresden Hbf | 50 vol.
LOAD: 245 vol.
- Hamburg Hbf | 80 vol.
- Bremen Hbf | 85 vol.
- Kiel Hbf | 80 vol.
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Dortmund Hbf | 70 vol.
- Osnabrück Hbf | 80 vol.
- Hannover Hbf | 60 vol.
LOAD: 185 vol.
- München Hbf | 100 vol.
- Stuttgart Hbf | 85 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: 1300 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 90, 80, 60, 60, 85, 50, 80, 100, 85, 0, 70, 60, 40, 0, 20, 0, 80, 25, 85, 80, 80, 0] ITERATION Generation: #1 Best cost: 7668.238 | Path: [1, 0, 12, 2, 16, 19, 1, 7, 13, 20, 3, 1, 8, 18, 10, 14, 1, 4, 22, 5, 21, 1, 6, 9, 1] Best cost: 7644.196 | Path: [1, 2, 16, 5, 12, 4, 1, 7, 13, 20, 3, 19, 1, 8, 18, 10, 14, 1, 22, 0, 21, 1, 9, 6, 1] Best cost: 7099.464 | Path: [1, 6, 14, 19, 3, 16, 7, 1, 8, 18, 10, 1, 4, 22, 12, 2, 1, 13, 20, 9, 1, 0, 5, 21, 1] Best cost: 7093.266 | Path: [1, 3, 19, 14, 6, 13, 1, 7, 20, 0, 12, 16, 1, 8, 18, 10, 1, 4, 22, 2, 5, 1, 9, 21, 1] Best cost: 7020.499 | Path: [1, 13, 20, 3, 19, 14, 1, 7, 0, 12, 2, 16, 1, 8, 18, 10, 1, 4, 22, 5, 21, 1, 9, 6, 1] Best cost: 7018.580 | Path: [1, 3, 19, 14, 6, 13, 1, 7, 4, 22, 12, 16, 1, 8, 18, 10, 1, 0, 20, 9, 1, 2, 5, 21, 1] Best cost: 6887.609 | Path: [1, 3, 19, 14, 6, 13, 1, 7, 20, 21, 16, 5, 1, 8, 18, 10, 1, 4, 22, 12, 2, 1, 0, 9, 1] Generation: #2 Best cost: 6860.229 | Path: [1, 3, 19, 14, 6, 13, 1, 7, 0, 12, 2, 16, 1, 8, 18, 10, 1, 4, 22, 5, 21, 1, 20, 9, 1] Best cost: 6637.125 | Path: [1, 2, 16, 5, 21, 14, 1, 7, 13, 20, 3, 19, 1, 8, 18, 10, 1, 4, 22, 12, 0, 1, 6, 9, 1] OPTIMIZING each tour... Current: [[1, 2, 16, 5, 21, 14, 1], [1, 7, 13, 20, 3, 19, 1], [1, 8, 18, 10, 1], [1, 4, 22, 12, 0, 1], [1, 6, 9, 1]] [2] Cost: 1362.338 to 1354.595 | Optimized: [1, 19, 3, 20, 13, 7, 1] [3] Cost: 975.065 to 959.498 | Optimized: [1, 8, 10, 18, 1] [4] Cost: 1107.771 to 1099.924 | Optimized: [1, 0, 12, 22, 4, 1] [5] Cost: 1443.850 to 1430.640 | Optimized: [1, 9, 6, 1] ACO RESULTS [1/290 vol./1748.101 km] Berlin Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Karlsruhe Hbf --> Berlin Hbf [2/300 vol./1354.595 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/245 vol./ 959.498 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [4/280 vol./1099.924 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [5/185 vol./1430.640 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6592.758 km.