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
- Kassel-Wilhelmshöhe (40 vol.)
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (100 vol.)
- Hannover Hbf (100 vol.)
- Stuttgart Hbf (55 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (65 vol.)
- Bremen Hbf (20 vol.)
- Dortmund Hbf (50 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (85 vol.)
- Köln Hbf (65 vol.)
- Kiel Hbf (35 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (45 vol.)
Tour 1
COST: 1464.023 km
LOAD: 290 vol.
- Ulm Hbf | 85 vol.
- Stuttgart Hbf | 55 vol.
- Karlsruhe Hbf | 100 vol.
- Würzburg Hbf | 50 vol.
Tour 2
COST: 1490.763 km
LOAD: 290 vol.
- Dortmund Hbf | 50 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 65 vol.
- Osnabrück Hbf | 45 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 35 vol.
Tour 3
COST: 1791.221 km
LOAD: 265 vol.
- München Hbf | 65 vol.
- Saarbrücken Hbf | 60 vol.
- Frankfurt Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 40 vol.
Tour 4
COST: 565.96 km
LOAD: 100 vol.
- Hannover Hbf | 100 vol.
LOAD: 290 vol.
- Ulm Hbf | 85 vol.
- Stuttgart Hbf | 55 vol.
- Karlsruhe Hbf | 100 vol.
- Würzburg Hbf | 50 vol.
LOAD: 290 vol.
- Dortmund Hbf | 50 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 65 vol.
- Osnabrück Hbf | 45 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 35 vol.
- Kiel Hbf | 35 vol.
LOAD: 265 vol.
- München Hbf | 65 vol.
- Saarbrücken Hbf | 60 vol.
- Frankfurt Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 40 vol.
LOAD: 100 vol.
- Hannover 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: 945 vol. | Vehicle capacity: 300 vol. Loads: [40, 0, 40, 100, 100, 0, 55, 0, 35, 65, 20, 0, 50, 0, 100, 85, 65, 0, 35, 0, 50, 60, 45, 0] ITERATION Generation: #1 Best cost: 6457.723 | Path: [1, 0, 12, 2, 16, 3, 1, 4, 10, 22, 8, 18, 20, 1, 9, 15, 6, 21, 1, 14, 1] Best cost: 5931.268 | Path: [1, 2, 16, 12, 0, 22, 10, 8, 1, 18, 4, 3, 20, 1, 21, 14, 6, 15, 1, 9, 1] Best cost: 5805.951 | Path: [1, 9, 15, 6, 20, 0, 1, 8, 18, 10, 4, 22, 12, 1, 2, 16, 21, 14, 1, 3, 1] Best cost: 5697.605 | Path: [1, 12, 2, 16, 22, 10, 8, 18, 1, 4, 0, 3, 20, 1, 6, 14, 21, 15, 1, 9, 1] Best cost: 5588.276 | Path: [1, 16, 2, 12, 22, 10, 8, 18, 1, 4, 0, 3, 20, 1, 15, 6, 14, 21, 1, 9, 1] Generation: #2 Best cost: 5584.974 | Path: [1, 16, 2, 12, 22, 10, 8, 18, 1, 4, 0, 3, 20, 1, 21, 14, 6, 15, 1, 9, 1] Generation: #4 Best cost: 5547.693 | Path: [1, 6, 14, 21, 16, 10, 1, 4, 22, 12, 2, 0, 1, 20, 3, 9, 15, 1, 8, 18, 1] Best cost: 5409.523 | Path: [1, 14, 6, 15, 20, 1, 8, 18, 10, 22, 12, 2, 16, 1, 0, 3, 21, 9, 1, 4, 1] OPTIMIZING each tour... Current: [[1, 14, 6, 15, 20, 1], [1, 8, 18, 10, 22, 12, 2, 16, 1], [1, 0, 3, 21, 9, 1], [1, 4, 1]] [1] Cost: 1526.811 to 1464.023 | Optimized: [1, 15, 6, 14, 20, 1] [2] Cost: 1522.247 to 1490.763 | Optimized: [1, 12, 2, 16, 22, 10, 8, 18, 1] [3] Cost: 1794.505 to 1791.221 | Optimized: [1, 9, 21, 3, 0, 1] ACO RESULTS [1/290 vol./1464.023 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Würzburg Hbf --> Berlin Hbf [2/290 vol./1490.763 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/265 vol./1791.221 km] Berlin Hbf -> München Hbf -> Saarbrücken Hbf -> Frankfurt Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/100 vol./ 565.960 km] Berlin Hbf -> Hannover Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5311.967 km.