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: 15 customers
- Düsseldorf Hbf (25 vol.)
- Aachen Hbf (25 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (60 vol.)
- Leipzig Hbf (45 vol.)
- Dortmund Hbf (95 vol.)
- Nürnberg Hbf (50 vol.)
- Karlsruhe Hbf (30 vol.)
- Ulm Hbf (60 vol.)
- Köln Hbf (60 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (75 vol.)
- Osnabrück Hbf (95 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1973.877 km
LOAD: 285 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 70 vol.
- Mainz Hbf | 75 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 25 vol.
- Düsseldorf Hbf | 25 vol.
Tour 2
COST: 1107.833 km
LOAD: 270 vol.
- Osnabrück Hbf | 95 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 35 vol.
Tour 3
COST: 1392.837 km
LOAD: 250 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 60 vol.
- Nürnberg Hbf | 50 vol.
- Leipzig Hbf | 45 vol.
Tour 4
COST: 981.267 km
LOAD: 95 vol.
- Dortmund Hbf | 95 vol.
LOAD: 285 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 70 vol.
- Mainz Hbf | 75 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 25 vol.
- Düsseldorf Hbf | 25 vol.
LOAD: 270 vol.
- Osnabrück Hbf | 95 vol.
- Bremen Hbf | 60 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 35 vol.
LOAD: 250 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 60 vol.
- Nürnberg Hbf | 50 vol.
- Leipzig Hbf | 45 vol.
LOAD: 95 vol.
- Dortmund 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: 900 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 25, 0, 0, 25, 0, 0, 80, 95, 60, 45, 95, 50, 30, 60, 60, 0, 35, 75, 0, 0, 95, 70] ITERATION Generation: #1 Best cost: 6232.206 | Path: [1, 2, 16, 5, 12, 22, 1, 11, 13, 9, 15, 14, 1, 8, 18, 10, 19, 1, 23, 1] Best cost: 6147.489 | Path: [1, 8, 18, 10, 22, 2, 1, 11, 13, 9, 15, 14, 1, 12, 16, 5, 19, 1, 23, 1] Best cost: 6136.973 | Path: [1, 18, 8, 10, 22, 2, 1, 11, 13, 9, 15, 14, 1, 19, 16, 5, 12, 1, 23, 1] Best cost: 6113.955 | Path: [1, 19, 14, 23, 15, 13, 1, 11, 10, 8, 18, 16, 1, 22, 12, 2, 5, 1, 9, 1] Best cost: 6106.839 | Path: [1, 23, 14, 15, 9, 11, 1, 8, 18, 22, 10, 2, 1, 13, 19, 16, 5, 1, 12, 1] Best cost: 5877.085 | Path: [1, 9, 15, 14, 23, 2, 1, 11, 13, 19, 5, 16, 18, 1, 8, 10, 22, 1, 12, 1] Best cost: 5867.751 | Path: [1, 23, 14, 19, 16, 2, 5, 1, 11, 13, 9, 15, 18, 1, 8, 10, 22, 1, 12, 1] Best cost: 5846.684 | Path: [1, 9, 15, 14, 23, 5, 1, 11, 13, 19, 16, 2, 18, 1, 8, 10, 22, 1, 12, 1] Best cost: 5838.152 | Path: [1, 12, 2, 16, 5, 19, 1, 11, 13, 9, 15, 14, 1, 8, 18, 10, 22, 1, 23, 1] Best cost: 5662.170 | Path: [1, 14, 23, 15, 9, 11, 1, 8, 18, 10, 22, 2, 1, 12, 16, 5, 19, 1, 13, 1] Best cost: 5594.282 | Path: [1, 19, 14, 23, 15, 13, 1, 11, 12, 2, 16, 5, 18, 1, 8, 10, 22, 1, 9, 1] Best cost: 5587.705 | Path: [1, 16, 2, 12, 22, 5, 1, 11, 9, 15, 14, 23, 1, 18, 8, 10, 13, 19, 1] Generation: #2 Best cost: 5579.849 | Path: [1, 11, 13, 9, 15, 14, 1, 8, 10, 22, 2, 5, 1, 12, 16, 19, 23, 1, 18, 1] Generation: #4 Best cost: 5528.557 | Path: [1, 14, 23, 19, 16, 2, 5, 1, 8, 18, 10, 22, 1, 11, 13, 9, 15, 1, 12, 1] OPTIMIZING each tour... Current: [[1, 14, 23, 19, 16, 2, 5, 1], [1, 8, 18, 10, 22, 1], [1, 11, 13, 9, 15, 1], [1, 12, 1]] [1] Cost: 2013.509 to 1973.877 | Optimized: [1, 14, 23, 19, 16, 5, 2, 1] [2] Cost: 1132.488 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] [3] Cost: 1401.293 to 1392.837 | Optimized: [1, 9, 15, 13, 11, 1] ACO RESULTS [1/285 vol./1973.877 km] Berlin Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Mainz Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf --> Berlin Hbf [2/270 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/250 vol./1392.837 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [4/ 95 vol./ 981.267 km] Berlin Hbf -> Dortmund Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5455.814 km.