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: 19 customers
- Kassel-Wilhelmshöhe (80 vol.)
- Düsseldorf Hbf (75 vol.)
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (30 vol.)
- Stuttgart Hbf (40 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (95 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (100 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (75 vol.)
- Ulm Hbf (75 vol.)
- Köln Hbf (45 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (30 vol.)
- Saarbrücken Hbf (65 vol.)
- Osnabrück Hbf (30 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1558.035 km
LOAD: 300 vol.
- Leipzig Hbf | 35 vol.
- Ulm Hbf | 75 vol.
- Stuttgart Hbf | 40 vol.
- Karlsruhe Hbf | 75 vol.
- Mainz Hbf | 30 vol.
- Frankfurt Hbf | 45 vol.
Tour 2
COST: 1960.127 km
LOAD: 295 vol.
- Dresden Hbf | 70 vol.
- Nürnberg Hbf | 40 vol.
- Freiburg Hbf | 90 vol.
- Saarbrücken Hbf | 65 vol.
- Osnabrück Hbf | 30 vol.
Tour 3
COST: 972.057 km
LOAD: 285 vol.
- Hannover Hbf | 30 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 70 vol.
Tour 4
COST: 1231.292 km
LOAD: 300 vol.
- Dortmund Hbf | 100 vol.
- Düsseldorf Hbf | 75 vol.
- Köln Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 80 vol.
LOAD: 300 vol.
- Leipzig Hbf | 35 vol.
- Ulm Hbf | 75 vol.
- Stuttgart Hbf | 40 vol.
- Karlsruhe Hbf | 75 vol.
- Mainz Hbf | 30 vol.
- Frankfurt Hbf | 45 vol.
LOAD: 295 vol.
- Dresden Hbf | 70 vol.
- Nürnberg Hbf | 40 vol.
- Freiburg Hbf | 90 vol.
- Saarbrücken Hbf | 65 vol.
- Osnabrück Hbf | 30 vol.
LOAD: 285 vol.
- Hannover Hbf | 30 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 70 vol.
LOAD: 300 vol.
- Dortmund Hbf | 100 vol.
- Düsseldorf Hbf | 75 vol.
- Köln Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 80 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: 1180 vol. | Vehicle capacity: 300 vol. Loads: [80, 0, 75, 45, 30, 0, 40, 70, 95, 0, 90, 35, 100, 40, 75, 75, 45, 0, 70, 30, 0, 65, 30, 90] ITERATION Generation: #1 Best cost: 7502.963 | Path: [1, 0, 12, 2, 16, 1, 7, 11, 3, 19, 21, 6, 1, 8, 18, 10, 4, 1, 22, 13, 15, 14, 1, 23, 1] Best cost: 5866.182 | Path: [1, 3, 19, 14, 6, 15, 11, 1, 7, 13, 21, 23, 22, 1, 4, 10, 8, 18, 1, 0, 12, 2, 16, 1] Best cost: 5747.338 | Path: [1, 15, 6, 14, 3, 19, 11, 1, 7, 13, 23, 21, 22, 1, 4, 10, 8, 18, 1, 12, 2, 16, 0, 1] Generation: #2 Best cost: 5723.236 | Path: [1, 3, 19, 14, 6, 15, 11, 1, 7, 13, 23, 21, 22, 1, 4, 10, 8, 18, 1, 0, 12, 2, 16, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 14, 6, 15, 11, 1], [1, 7, 13, 23, 21, 22, 1], [1, 4, 10, 8, 18, 1], [1, 0, 12, 2, 16, 1]] [1] Cost: 1558.250 to 1558.035 | Optimized: [1, 11, 15, 6, 14, 19, 3, 1] [4] Cost: 1232.802 to 1231.292 | Optimized: [1, 12, 2, 16, 0, 1] ACO RESULTS [1/300 vol./1558.035 km] Berlin Hbf -> Leipzig Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/295 vol./1960.127 km] Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Osnabrück Hbf --> Berlin Hbf [3/285 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/300 vol./1231.292 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5721.511 km.