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: 15 customers
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (100 vol.)
- Hannover Hbf (50 vol.)
- Stuttgart Hbf (55 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (75 vol.)
- Bremen Hbf (95 vol.)
- Dortmund Hbf (55 vol.)
- Ulm Hbf (55 vol.)
- Köln Hbf (100 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (95 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (80 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 2060.516 km
LOAD: 290 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 55 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 20 vol.
- Düsseldorf Hbf | 40 vol.
Tour 2
COST: 972.057 km
LOAD: 255 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 20 vol.
Tour 3
COST: 1208.086 km
LOAD: 235 vol.
- Dortmund Hbf | 55 vol.
- Köln Hbf | 100 vol.
- Osnabrück Hbf | 80 vol.
Tour 4
COST: 1158.667 km
LOAD: 195 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 100 vol.
LOAD: 290 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 55 vol.
- Stuttgart Hbf | 55 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 20 vol.
- Düsseldorf Hbf | 40 vol.
LOAD: 255 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 20 vol.
LOAD: 235 vol.
- Dortmund Hbf | 55 vol.
- Köln Hbf | 100 vol.
- Osnabrück Hbf | 80 vol.
LOAD: 195 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 100 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: 975 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 40, 100, 50, 0, 55, 0, 90, 75, 95, 0, 55, 0, 0, 55, 100, 0, 20, 95, 0, 20, 80, 45] ITERATION Generation: #1 Best cost: 6236.659 | Path: [1, 2, 16, 12, 22, 18, 1, 8, 10, 4, 6, 1, 3, 19, 21, 23, 1, 9, 15, 1] Best cost: 6038.303 | Path: [1, 6, 15, 9, 23, 21, 4, 1, 8, 18, 10, 22, 1, 2, 16, 12, 3, 1, 19, 1] Best cost: 6029.809 | Path: [1, 8, 18, 10, 22, 1, 4, 12, 2, 16, 21, 1, 15, 6, 23, 3, 1, 9, 19, 1] Best cost: 5935.977 | Path: [1, 9, 15, 6, 3, 1, 8, 18, 10, 22, 1, 4, 12, 2, 16, 21, 1, 19, 23, 1] Best cost: 5876.666 | Path: [1, 8, 18, 10, 22, 1, 4, 12, 2, 16, 21, 1, 3, 19, 6, 23, 1, 9, 15, 1] Best cost: 5856.557 | Path: [1, 23, 6, 15, 9, 21, 2, 1, 4, 10, 8, 18, 1, 22, 12, 16, 1, 19, 3, 1] Best cost: 5682.723 | Path: [1, 6, 15, 9, 23, 21, 2, 1, 8, 18, 10, 4, 1, 22, 12, 16, 1, 19, 3, 1] Best cost: 5629.420 | Path: [1, 9, 15, 6, 23, 21, 2, 1, 8, 18, 10, 22, 1, 4, 12, 16, 19, 1, 3, 1] Best cost: 5402.617 | Path: [1, 9, 15, 6, 23, 21, 2, 1, 4, 10, 8, 18, 1, 3, 19, 16, 1, 12, 22, 1] Best cost: 5400.441 | Path: [1, 9, 15, 6, 23, 21, 2, 1, 4, 10, 8, 18, 1, 12, 16, 22, 1, 3, 19, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 23, 21, 2, 1], [1, 4, 10, 8, 18, 1], [1, 12, 16, 22, 1], [1, 3, 19, 1]] [4] Cost: 1159.782 to 1158.667 | Optimized: [1, 19, 3, 1] ACO RESULTS [1/290 vol./2060.516 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Düsseldorf Hbf --> Berlin Hbf [2/255 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/235 vol./1208.086 km] Berlin Hbf -> Dortmund Hbf -> Köln Hbf -> Osnabrück Hbf --> Berlin Hbf [4/195 vol./1158.667 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5399.326 km.