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 (40 vol.)
- Düsseldorf Hbf (75 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (70 vol.)
- Leipzig Hbf (80 vol.)
- Nürnberg Hbf (80 vol.)
- Ulm Hbf (25 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (40 vol.)
- Kiel Hbf (100 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (25 vol.)
- Osnabrück Hbf (40 vol.)
Tour 1
COST: 1515.031 km
LOAD: 300 vol.
- Ulm Hbf | 25 vol.
- Stuttgart Hbf | 20 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 80 vol.
- Dresden Hbf | 95 vol.
Tour 2
COST: 881.934 km
LOAD: 285 vol.
- Hannover Hbf | 85 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 100 vol.
Tour 3
COST: 1748.725 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Frankfurt Hbf | 80 vol.
- Mannheim Hbf | 40 vol.
- Saarbrücken Hbf | 25 vol.
- Aachen Hbf | 75 vol.
- Osnabrück Hbf | 40 vol.
Tour 4
COST: 1755.098 km
LOAD: 300 vol.
- München Hbf | 70 vol.
- Würzburg Hbf | 90 vol.
- Köln Hbf | 65 vol.
- Düsseldorf Hbf | 75 vol.
LOAD: 300 vol.
- Ulm Hbf | 25 vol.
- Stuttgart Hbf | 20 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 80 vol.
- Dresden Hbf | 95 vol.
LOAD: 285 vol.
- Hannover Hbf | 85 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 100 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Frankfurt Hbf | 80 vol.
- Mannheim Hbf | 40 vol.
- Saarbrücken Hbf | 25 vol.
- Aachen Hbf | 75 vol.
- Osnabrück Hbf | 40 vol.
LOAD: 300 vol.
- München Hbf | 70 vol.
- Würzburg Hbf | 90 vol.
- Köln Hbf | 65 vol.
- Düsseldorf Hbf | 75 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: 1185 vol. | Vehicle capacity: 300 vol. Loads: [40, 0, 75, 80, 85, 75, 20, 95, 100, 70, 0, 80, 0, 80, 0, 25, 65, 40, 100, 0, 90, 25, 40, 0] ITERATION Generation: #1 Best cost: 6869.638 | Path: [1, 0, 11, 7, 13, 1, 4, 8, 18, 1, 2, 16, 5, 3, 1, 22, 17, 21, 6, 15, 9, 1, 20, 1] Best cost: 6139.160 | Path: [1, 7, 11, 13, 6, 15, 1, 20, 3, 17, 21, 16, 1, 8, 18, 4, 1, 0, 22, 2, 5, 9, 1] Best cost: 6130.670 | Path: [1, 11, 7, 13, 15, 6, 1, 4, 8, 18, 1, 20, 3, 17, 21, 16, 1, 0, 22, 2, 5, 9, 1] Best cost: 6104.765 | Path: [1, 4, 8, 18, 1, 11, 7, 13, 15, 6, 1, 0, 3, 17, 21, 5, 22, 1, 20, 9, 16, 2, 1] Generation: #3 Best cost: 6088.671 | Path: [1, 18, 8, 4, 1, 11, 7, 13, 15, 6, 1, 22, 0, 3, 17, 21, 5, 1, 9, 20, 16, 2, 1] Generation: #6 Best cost: 5961.295 | Path: [1, 11, 7, 13, 15, 6, 1, 8, 18, 4, 1, 0, 3, 17, 21, 5, 22, 1, 9, 20, 16, 2, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 13, 15, 6, 1], [1, 8, 18, 4, 1], [1, 0, 3, 17, 21, 5, 22, 1], [1, 9, 20, 16, 2, 1]] [1] Cost: 1542.379 to 1515.031 | Optimized: [1, 15, 6, 13, 11, 7, 1] [2] Cost: 915.093 to 881.934 | Optimized: [1, 4, 8, 18, 1] ACO RESULTS [1/300 vol./1515.031 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [2/285 vol./ 881.934 km] Berlin Hbf -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/300 vol./1748.725 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Osnabrück Hbf --> Berlin Hbf [4/300 vol./1755.098 km] Berlin Hbf -> München Hbf -> Würzburg Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5900.788 km.