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: 18 customers
- Kassel-Wilhelmshöhe (65 vol.)
- Düsseldorf Hbf (60 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (65 vol.)
- Stuttgart Hbf (90 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (65 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (40 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (45 vol.)
- Köln Hbf (50 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (85 vol.)
- Mainz Hbf (90 vol.)
- Würzburg Hbf (40 vol.)
- Osnabrück Hbf (45 vol.)
Tour 1
COST: 1505.111 km
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 65 vol.
- Leipzig Hbf | 50 vol.
Tour 2
COST: 1113.837 km
LOAD: 265 vol.
- Hannover Hbf | 40 vol.
- Osnabrück Hbf | 45 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 85 vol.
Tour 3
COST: 1430.419 km
LOAD: 300 vol.
- Mainz Hbf | 90 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 45 vol.
- Stuttgart Hbf | 90 vol.
Tour 4
COST: 1308.428 km
LOAD: 215 vol.
- Dortmund Hbf | 40 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 50 vol.
- Aachen Hbf | 65 vol.
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 65 vol.
- Leipzig Hbf | 50 vol.
LOAD: 265 vol.
- Hannover Hbf | 40 vol.
- Osnabrück Hbf | 45 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 85 vol.
LOAD: 300 vol.
- Mainz Hbf | 90 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 45 vol.
- Stuttgart Hbf | 90 vol.
LOAD: 215 vol.
- Dortmund Hbf | 40 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 50 vol.
- Aachen Hbf | 65 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: [65, 0, 60, 0, 40, 65, 90, 0, 20, 65, 75, 50, 40, 65, 45, 0, 50, 75, 85, 90, 40, 0, 45, 0] ITERATION Generation: #1 Best cost: 6385.701 | Path: [1, 0, 4, 8, 18, 10, 1, 11, 20, 13, 9, 14, 1, 12, 2, 16, 5, 17, 1, 22, 19, 6, 1] Best cost: 6054.007 | Path: [1, 2, 16, 5, 12, 22, 4, 1, 11, 0, 20, 13, 9, 1, 18, 8, 10, 19, 1, 14, 17, 6, 1] Best cost: 5775.087 | Path: [1, 5, 2, 16, 12, 22, 4, 1, 11, 13, 20, 19, 14, 1, 8, 18, 10, 0, 1, 9, 6, 17, 1] Best cost: 5610.310 | Path: [1, 14, 17, 19, 20, 11, 1, 8, 18, 4, 10, 22, 1, 12, 2, 16, 5, 0, 1, 13, 9, 6, 1] Best cost: 5606.940 | Path: [1, 19, 17, 14, 6, 1, 11, 4, 10, 8, 18, 1, 22, 12, 2, 16, 5, 20, 1, 0, 13, 9, 1] Best cost: 5555.619 | Path: [1, 0, 12, 2, 16, 5, 8, 1, 11, 20, 19, 17, 14, 1, 4, 22, 10, 18, 1, 13, 9, 6, 1] Generation: #2 Best cost: 5531.085 | Path: [1, 17, 14, 6, 20, 11, 1, 8, 18, 10, 22, 4, 1, 0, 12, 2, 16, 5, 1, 13, 9, 19, 1] Generation: #4 Best cost: 5520.539 | Path: [1, 2, 16, 5, 12, 22, 4, 1, 11, 0, 20, 6, 14, 1, 13, 9, 17, 19, 1, 8, 18, 10, 1] Generation: #5 Best cost: 5516.994 | Path: [1, 2, 16, 5, 12, 22, 4, 1, 11, 13, 20, 19, 14, 1, 0, 17, 6, 9, 1, 8, 18, 10, 1] Generation: #7 Best cost: 5410.156 | Path: [1, 11, 0, 20, 13, 9, 1, 8, 18, 10, 22, 4, 1, 19, 17, 14, 6, 1, 12, 2, 16, 5, 1] OPTIMIZING each tour... Current: [[1, 11, 0, 20, 13, 9, 1], [1, 8, 18, 10, 22, 4, 1], [1, 19, 17, 14, 6, 1], [1, 12, 2, 16, 5, 1]] [1] Cost: 1534.362 to 1505.111 | Optimized: [1, 0, 20, 13, 9, 11, 1] [2] Cost: 1136.947 to 1113.837 | Optimized: [1, 4, 22, 10, 8, 18, 1] ACO RESULTS [1/285 vol./1505.111 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Leipzig Hbf --> Berlin Hbf [2/265 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/300 vol./1430.419 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf --> Berlin Hbf [4/215 vol./1308.428 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5357.795 km.