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
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (65 vol.)
- Hamburg Hbf (30 vol.)
- München Hbf (35 vol.)
- Bremen Hbf (60 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (45 vol.)
- Köln Hbf (60 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (85 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1308.428 km
LOAD: 285 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 65 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 75 vol.
Tour 2
COST: 1974.967 km
LOAD: 285 vol.
- Dresden Hbf | 65 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 35 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 20 vol.
- Mainz Hbf | 20 vol.
- Frankfurt Hbf | 45 vol.
Tour 3
COST: 1113.837 km
LOAD: 260 vol.
- Hannover Hbf | 65 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 20 vol.
Tour 4
COST: 1492.741 km
LOAD: 135 vol.
- Saarbrücken Hbf | 85 vol.
- Würzburg Hbf | 50 vol.
LOAD: 285 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 65 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 75 vol.
LOAD: 285 vol.
- Dresden Hbf | 65 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 35 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 20 vol.
- Mainz Hbf | 20 vol.
- Frankfurt Hbf | 45 vol.
LOAD: 260 vol.
- Hannover Hbf | 65 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 20 vol.
LOAD: 135 vol.
- Saarbrücken Hbf | 85 vol.
- Würzburg Hbf | 50 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: 965 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 65, 45, 65, 75, 30, 65, 30, 35, 60, 0, 85, 25, 45, 0, 60, 0, 20, 20, 50, 85, 85, 20] ITERATION Generation: #1 Best cost: 6255.703 | Path: [1, 2, 16, 5, 12, 1, 7, 20, 13, 9, 6, 14, 23, 19, 1, 4, 10, 8, 18, 22, 1, 3, 21, 1] Best cost: 6191.596 | Path: [1, 2, 16, 5, 12, 1, 7, 20, 13, 9, 6, 14, 23, 19, 1, 8, 18, 4, 10, 22, 1, 3, 21, 1] Best cost: 6161.029 | Path: [1, 5, 16, 2, 12, 1, 7, 20, 13, 9, 14, 6, 23, 19, 1, 8, 18, 10, 22, 4, 1, 3, 21, 1] Generation: #2 Best cost: 6031.919 | Path: [1, 2, 16, 5, 12, 1, 7, 20, 13, 9, 6, 14, 23, 19, 1, 8, 18, 10, 22, 4, 1, 3, 21, 1] Best cost: 5947.416 | Path: [1, 5, 2, 16, 12, 1, 7, 13, 9, 6, 14, 23, 19, 3, 1, 8, 18, 10, 22, 4, 1, 20, 21, 1] OPTIMIZING each tour... Current: [[1, 5, 2, 16, 12, 1], [1, 7, 13, 9, 6, 14, 23, 19, 3, 1], [1, 8, 18, 10, 22, 4, 1], [1, 20, 21, 1]] [1] Cost: 1340.994 to 1308.428 | Optimized: [1, 12, 2, 16, 5, 1] [3] Cost: 1136.947 to 1113.837 | Optimized: [1, 4, 22, 10, 8, 18, 1] [4] Cost: 1494.508 to 1492.741 | Optimized: [1, 21, 20, 1] ACO RESULTS [1/285 vol./1308.428 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf [2/285 vol./1974.967 km] Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [3/260 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/135 vol./1492.741 km] Berlin Hbf -> Saarbrücken Hbf -> Würzburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5889.973 km.