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: 16 customers
- Düsseldorf Hbf (25 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (35 vol.)
- Stuttgart Hbf (100 vol.)
- Hamburg Hbf (70 vol.)
- München Hbf (75 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (95 vol.)
- Karlsruhe Hbf (45 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (45 vol.)
- Freiburg Hbf (40 vol.)
Tour 1
COST: 1476.784 km
LOAD: 290 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 25 vol.
- Aachen Hbf | 35 vol.
- Osnabrück Hbf | 45 vol.
- Hannover Hbf | 55 vol.
- Hamburg Hbf | 70 vol.
Tour 2
COST: 1059.979 km
LOAD: 285 vol.
- Würzburg Hbf | 90 vol.
- Nürnberg Hbf | 95 vol.
- Leipzig Hbf | 100 vol.
Tour 3
COST: 1818.365 km
LOAD: 260 vol.
- München Hbf | 75 vol.
- Stuttgart Hbf | 100 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 40 vol.
Tour 4
COST: 1457.258 km
LOAD: 230 vol.
- Saarbrücken Hbf | 100 vol.
- Mainz Hbf | 75 vol.
- Frankfurt Hbf | 55 vol.
LOAD: 290 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 25 vol.
- Aachen Hbf | 35 vol.
- Osnabrück Hbf | 45 vol.
- Hannover Hbf | 55 vol.
- Hamburg Hbf | 70 vol.
LOAD: 285 vol.
- Würzburg Hbf | 90 vol.
- Nürnberg Hbf | 95 vol.
- Leipzig Hbf | 100 vol.
LOAD: 260 vol.
- München Hbf | 75 vol.
- Stuttgart Hbf | 100 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 40 vol.
LOAD: 230 vol.
- Saarbrücken Hbf | 100 vol.
- Mainz Hbf | 75 vol.
- Frankfurt Hbf | 55 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: 1065 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 25, 55, 55, 35, 100, 0, 70, 75, 0, 100, 60, 95, 45, 0, 0, 0, 0, 75, 90, 100, 45, 40] ITERATION Generation: #1 Best cost: 6479.650 | Path: [1, 2, 12, 5, 21, 19, 1, 11, 13, 20, 1, 4, 8, 22, 3, 14, 1, 6, 23, 9, 1] Best cost: 6346.763 | Path: [1, 4, 22, 12, 2, 5, 14, 1, 11, 13, 20, 1, 8, 19, 3, 21, 1, 9, 6, 23, 1] Best cost: 6023.572 | Path: [1, 5, 2, 12, 22, 4, 8, 1, 11, 13, 20, 1, 19, 3, 14, 6, 1, 9, 21, 23, 1] Best cost: 5979.012 | Path: [1, 6, 14, 21, 3, 1, 11, 13, 20, 1, 8, 4, 22, 12, 2, 5, 1, 9, 23, 19, 1] Best cost: 5924.232 | Path: [1, 8, 4, 22, 12, 2, 5, 1, 11, 13, 20, 1, 6, 14, 23, 21, 1, 3, 19, 9, 1] Best cost: 5905.039 | Path: [1, 5, 2, 12, 22, 4, 8, 1, 11, 13, 20, 1, 3, 19, 14, 6, 1, 9, 23, 21, 1] Best cost: 5819.730 | Path: [1, 5, 2, 12, 22, 4, 8, 1, 11, 13, 20, 1, 9, 6, 14, 23, 1, 3, 19, 21, 1] Best cost: 5816.935 | Path: [1, 12, 2, 5, 22, 4, 8, 1, 11, 13, 20, 1, 9, 6, 14, 23, 1, 3, 19, 21, 1] OPTIMIZING each tour... Current: [[1, 12, 2, 5, 22, 4, 8, 1], [1, 11, 13, 20, 1], [1, 9, 6, 14, 23, 1], [1, 3, 19, 21, 1]] [2] Cost: 1063.904 to 1059.979 | Optimized: [1, 20, 13, 11, 1] [4] Cost: 1457.882 to 1457.258 | Optimized: [1, 21, 19, 3, 1] ACO RESULTS [1/290 vol./1476.784 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Osnabrück Hbf -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf [2/285 vol./1059.979 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [3/260 vol./1818.365 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [4/230 vol./1457.258 km] Berlin Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5812.386 km.