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 (95 vol.)
- Düsseldorf Hbf (60 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (90 vol.)
- Leipzig Hbf (80 vol.)
- Nürnberg Hbf (100 vol.)
- Ulm Hbf (90 vol.)
- Köln Hbf (40 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (45 vol.)
- Saarbrücken Hbf (95 vol.)
- Osnabrück Hbf (30 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1647.149 km
LOAD: 290 vol.
- Mainz Hbf | 45 vol.
- Saarbrücken Hbf | 95 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 40 vol.
- Düsseldorf Hbf | 60 vol.
Tour 2
COST: 1228.383 km
LOAD: 270 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 80 vol.
- Hannover Hbf | 65 vol.
- Osnabrück Hbf | 30 vol.
- Hamburg Hbf | 20 vol.
Tour 3
COST: 1357.805 km
LOAD: 280 vol.
- München Hbf | 90 vol.
- Ulm Hbf | 90 vol.
- Nürnberg Hbf | 100 vol.
Tour 4
COST: 1698.914 km
LOAD: 275 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Mannheim Hbf | 70 vol.
- Freiburg Hbf | 50 vol.
- Stuttgart Hbf | 60 vol.
Tour 5
COST: 701.943 km
LOAD: 100 vol.
- Kiel Hbf | 100 vol.
LOAD: 290 vol.
- Mainz Hbf | 45 vol.
- Saarbrücken Hbf | 95 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 40 vol.
- Düsseldorf Hbf | 60 vol.
LOAD: 270 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 80 vol.
- Hannover Hbf | 65 vol.
- Osnabrück Hbf | 30 vol.
- Hamburg Hbf | 20 vol.
LOAD: 280 vol.
- München Hbf | 90 vol.
- Ulm Hbf | 90 vol.
- Nürnberg Hbf | 100 vol.
LOAD: 275 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Mannheim Hbf | 70 vol.
- Freiburg Hbf | 50 vol.
- Stuttgart Hbf | 60 vol.
LOAD: 100 vol.
- Kiel 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: 1215 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 60, 0, 65, 50, 60, 75, 20, 90, 0, 80, 0, 100, 0, 90, 40, 70, 100, 45, 0, 95, 30, 50] ITERATION Generation: #1 Best cost: 7861.588 | Path: [1, 0, 22, 4, 8, 11, 1, 7, 13, 9, 1, 18, 2, 16, 5, 19, 1, 23, 6, 15, 17, 1, 21, 1] Best cost: 7658.158 | Path: [1, 4, 22, 0, 19, 6, 1, 7, 11, 8, 18, 1, 13, 15, 9, 1, 17, 21, 5, 2, 1, 16, 23, 1] Best cost: 7448.226 | Path: [1, 8, 18, 4, 22, 2, 1, 7, 11, 0, 19, 1, 13, 9, 15, 1, 6, 17, 21, 23, 1, 16, 5, 1] Best cost: 7409.300 | Path: [1, 22, 4, 8, 18, 11, 1, 7, 13, 9, 1, 0, 19, 17, 6, 1, 2, 16, 5, 21, 23, 1, 15, 1] Best cost: 7142.757 | Path: [1, 8, 18, 22, 4, 11, 1, 7, 13, 9, 1, 0, 2, 16, 5, 19, 1, 17, 21, 23, 6, 1, 15, 1] Best cost: 7131.373 | Path: [1, 6, 15, 9, 23, 1, 7, 11, 8, 18, 1, 4, 22, 16, 2, 5, 19, 1, 13, 17, 21, 1, 0, 1] Generation: #2 Best cost: 7038.817 | Path: [1, 9, 15, 6, 23, 1, 11, 7, 13, 19, 1, 4, 22, 16, 2, 5, 8, 1, 0, 17, 21, 1, 18, 1] Best cost: 7010.587 | Path: [1, 9, 15, 6, 23, 1, 11, 7, 13, 19, 1, 4, 22, 2, 16, 5, 8, 1, 0, 17, 21, 1, 18, 1] Generation: #5 Best cost: 6912.539 | Path: [1, 2, 16, 5, 21, 19, 1, 7, 11, 4, 8, 22, 1, 13, 9, 15, 1, 0, 17, 6, 23, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 2, 16, 5, 21, 19, 1], [1, 7, 11, 4, 8, 22, 1], [1, 13, 9, 15, 1], [1, 0, 17, 6, 23, 1], [1, 18, 1]] [1] Cost: 1652.451 to 1647.149 | Optimized: [1, 19, 21, 5, 16, 2, 1] [2] Cost: 1377.394 to 1228.383 | Optimized: [1, 7, 11, 4, 22, 8, 1] [3] Cost: 1366.321 to 1357.805 | Optimized: [1, 9, 15, 13, 1] [4] Cost: 1814.430 to 1698.914 | Optimized: [1, 0, 17, 23, 6, 1] ACO RESULTS [1/290 vol./1647.149 km] Berlin Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf [2/270 vol./1228.383 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Osnabrück Hbf -> Hamburg Hbf --> Berlin Hbf [3/280 vol./1357.805 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf --> Berlin Hbf [4/275 vol./1698.914 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Mannheim Hbf -> Freiburg Hbf -> Stuttgart Hbf --> Berlin Hbf [5/100 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6634.194 km.