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: 20 customers
- Kassel-Wilhelmshöhe (20 vol.)
- Frankfurt Hbf (75 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (45 vol.)
- Dresden Hbf (100 vol.)
- Hamburg Hbf (30 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (60 vol.)
- Dortmund Hbf (25 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (60 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (60 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1749.349 km
LOAD: 300 vol.
- Mannheim Hbf | 60 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 60 vol.
- Mainz Hbf | 35 vol.
Tour 2
COST: 1272.423 km
LOAD: 295 vol.
- Hamburg Hbf | 30 vol.
- Bremen Hbf | 60 vol.
- Hannover Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Dresden Hbf | 100 vol.
Tour 3
COST: 1804.158 km
LOAD: 285 vol.
- Kiel Hbf | 35 vol.
- Dortmund Hbf | 25 vol.
- Aachen Hbf | 30 vol.
- Köln Hbf | 70 vol.
- Frankfurt Hbf | 75 vol.
- Würzburg Hbf | 50 vol.
Tour 4
COST: 1458.561 km
LOAD: 250 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 45 vol.
- Nürnberg Hbf | 85 vol.
LOAD: 300 vol.
- Mannheim Hbf | 60 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 60 vol.
- Mainz Hbf | 35 vol.
LOAD: 295 vol.
- Hamburg Hbf | 30 vol.
- Bremen Hbf | 60 vol.
- Hannover Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Dresden Hbf | 100 vol.
LOAD: 285 vol.
- Kiel Hbf | 35 vol.
- Dortmund Hbf | 25 vol.
- Aachen Hbf | 30 vol.
- Köln Hbf | 70 vol.
- Frankfurt Hbf | 75 vol.
- Würzburg Hbf | 50 vol.
LOAD: 250 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 45 vol.
- Nürnberg 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: 1130 vol. | Vehicle capacity: 300 vol. Loads: [20, 0, 0, 75, 85, 30, 45, 100, 30, 100, 60, 0, 25, 85, 100, 20, 70, 60, 35, 35, 50, 60, 0, 45] ITERATION Generation: #1 Best cost: 7169.181 | Path: [1, 0, 12, 16, 5, 17, 19, 21, 1, 7, 13, 20, 6, 15, 1, 8, 10, 4, 18, 3, 1, 9, 23, 14, 1] Best cost: 7021.463 | Path: [1, 4, 10, 8, 18, 12, 5, 19, 1, 7, 13, 20, 6, 15, 1, 0, 3, 17, 14, 23, 1, 9, 21, 16, 1] Best cost: 6932.884 | Path: [1, 8, 10, 4, 0, 12, 16, 1, 7, 13, 20, 6, 15, 1, 18, 3, 19, 17, 21, 5, 1, 14, 23, 9, 1] Best cost: 6572.886 | Path: [1, 13, 20, 3, 19, 5, 12, 1, 7, 9, 15, 6, 0, 1, 8, 18, 10, 4, 16, 1, 17, 14, 23, 21, 1] Best cost: 6525.331 | Path: [1, 20, 13, 9, 15, 6, 1, 7, 0, 4, 10, 8, 1, 18, 12, 16, 5, 19, 3, 1, 17, 14, 21, 23, 1] Generation: #2 Best cost: 6436.924 | Path: [1, 19, 3, 17, 14, 15, 1, 7, 9, 13, 1, 18, 8, 10, 4, 12, 5, 0, 1, 20, 6, 23, 21, 16, 1] Best cost: 6336.356 | Path: [1, 21, 23, 14, 17, 19, 1, 7, 0, 4, 10, 8, 1, 18, 12, 16, 5, 3, 20, 1, 9, 15, 6, 13, 1] OPTIMIZING each tour... Current: [[1, 21, 23, 14, 17, 19, 1], [1, 7, 0, 4, 10, 8, 1], [1, 18, 12, 16, 5, 3, 20, 1], [1, 9, 15, 6, 13, 1]] [1] Cost: 1789.910 to 1749.349 | Optimized: [1, 17, 14, 23, 21, 19, 1] [2] Cost: 1274.093 to 1272.423 | Optimized: [1, 8, 10, 4, 0, 7, 1] [3] Cost: 1813.792 to 1804.158 | Optimized: [1, 18, 12, 5, 16, 3, 20, 1] ACO RESULTS [1/300 vol./1749.349 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf --> Berlin Hbf [2/295 vol./1272.423 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Hannover Hbf -> Kassel-Wilhelmshöhe -> Dresden Hbf --> Berlin Hbf [3/285 vol./1804.158 km] Berlin Hbf -> Kiel Hbf -> Dortmund Hbf -> Aachen Hbf -> Köln Hbf -> Frankfurt Hbf -> Würzburg Hbf --> Berlin Hbf [4/250 vol./1458.561 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6284.491 km.