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 (70 vol.)
- Düsseldorf Hbf (50 vol.)
- Aachen Hbf (90 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (20 vol.)
- Bremen Hbf (75 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (30 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (30 vol.)
- Ulm Hbf (60 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (50 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1763.883 km
LOAD: 290 vol.
- Leipzig Hbf | 35 vol.
- Ulm Hbf | 60 vol.
- Stuttgart Hbf | 95 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 70 vol.
Tour 2
COST: 1646.291 km
LOAD: 300 vol.
- Düsseldorf Hbf | 50 vol.
- Aachen Hbf | 90 vol.
- Mainz Hbf | 50 vol.
- Nürnberg Hbf | 85 vol.
- Dresden Hbf | 25 vol.
Tour 3
COST: 1200.608 km
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Dortmund Hbf | 30 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 20 vol.
Tour 4
COST: 701.943 km
LOAD: 95 vol.
- Kiel Hbf | 95 vol.
LOAD: 290 vol.
- Leipzig Hbf | 35 vol.
- Ulm Hbf | 60 vol.
- Stuttgart Hbf | 95 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 70 vol.
LOAD: 300 vol.
- Düsseldorf Hbf | 50 vol.
- Aachen Hbf | 90 vol.
- Mainz Hbf | 50 vol.
- Nürnberg Hbf | 85 vol.
- Dresden Hbf | 25 vol.
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Dortmund Hbf | 30 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 75 vol.
- Hamburg Hbf | 20 vol.
LOAD: 95 vol.
- Kiel Hbf | 95 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: 970 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 50, 0, 0, 90, 95, 25, 20, 0, 75, 35, 30, 85, 30, 60, 0, 0, 95, 50, 0, 0, 90, 70] ITERATION Generation: #1 Best cost: 6139.295 | Path: [1, 0, 12, 2, 5, 19, 1, 11, 7, 13, 6, 14, 8, 1, 18, 10, 22, 1, 15, 23, 1] Best cost: 6100.904 | Path: [1, 8, 18, 10, 22, 1, 11, 7, 13, 6, 14, 12, 1, 0, 2, 5, 19, 1, 15, 23, 1] Best cost: 5851.311 | Path: [1, 14, 6, 15, 13, 7, 1, 11, 0, 12, 2, 5, 8, 1, 18, 10, 22, 1, 19, 23, 1] Best cost: 5756.748 | Path: [1, 19, 14, 6, 15, 11, 7, 1, 8, 18, 10, 22, 1, 0, 12, 2, 5, 1, 13, 23, 1] Best cost: 5749.902 | Path: [1, 22, 10, 8, 18, 1, 7, 11, 13, 15, 6, 1, 0, 12, 2, 5, 19, 1, 14, 23, 1] Best cost: 5621.668 | Path: [1, 5, 2, 12, 22, 8, 1, 7, 11, 13, 15, 6, 1, 0, 19, 14, 23, 10, 1, 18, 1] Best cost: 5594.953 | Path: [1, 23, 14, 6, 15, 11, 1, 7, 13, 19, 5, 2, 1, 8, 18, 10, 22, 1, 0, 12, 1] Best cost: 5468.336 | Path: [1, 15, 6, 14, 23, 12, 1, 8, 10, 22, 0, 11, 1, 7, 13, 19, 2, 5, 1, 18, 1] Generation: #2 Best cost: 5376.225 | Path: [1, 23, 14, 6, 15, 11, 1, 7, 13, 19, 2, 5, 1, 0, 12, 22, 10, 8, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 23, 14, 6, 15, 11, 1], [1, 7, 13, 19, 2, 5, 1], [1, 0, 12, 22, 10, 8, 1], [1, 18, 1]] [1] Cost: 1769.492 to 1763.883 | Optimized: [1, 11, 15, 6, 14, 23, 1] [2] Cost: 1704.182 to 1646.291 | Optimized: [1, 2, 5, 19, 13, 7, 1] ACO RESULTS [1/290 vol./1763.883 km] Berlin Hbf -> Leipzig Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [2/300 vol./1646.291 km] Berlin Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Mainz Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/285 vol./1200.608 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [4/ 95 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5312.725 km.