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: 17 customers
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (65 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (25 vol.)
- Stuttgart Hbf (100 vol.)
- Dresden Hbf (65 vol.)
- Hamburg Hbf (30 vol.)
- Bremen Hbf (70 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (30 vol.)
- Ulm Hbf (65 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (45 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (35 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1849.647 km
LOAD: 300 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 100 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 100 vol.
Tour 2
COST: 1421.45 km
LOAD: 280 vol.
- Frankfurt Hbf | 65 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 75 vol.
- Nürnberg Hbf | 30 vol.
- Dresden Hbf | 65 vol.
Tour 3
COST: 1113.837 km
LOAD: 300 vol.
- Hannover Hbf | 100 vol.
- Osnabrück Hbf | 35 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 65 vol.
Tour 4
COST: 1272.297 km
LOAD: 205 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 95 vol.
- Aachen Hbf | 25 vol.
LOAD: 300 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 100 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 100 vol.
LOAD: 280 vol.
- Frankfurt Hbf | 65 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 75 vol.
- Nürnberg Hbf | 30 vol.
- Dresden Hbf | 65 vol.
LOAD: 300 vol.
- Hannover Hbf | 100 vol.
- Osnabrück Hbf | 35 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 65 vol.
LOAD: 205 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 95 vol.
- Aachen Hbf | 25 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: 1085 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 95, 65, 100, 25, 100, 65, 30, 0, 70, 0, 85, 30, 0, 65, 0, 75, 65, 45, 0, 100, 35, 35] ITERATION Generation: #1 Best cost: 6859.916 | Path: [1, 2, 5, 12, 22, 8, 13, 1, 7, 4, 10, 18, 1, 19, 3, 17, 6, 1, 15, 21, 23, 1] Best cost: 5975.792 | Path: [1, 3, 19, 17, 21, 1, 7, 13, 15, 6, 23, 1, 4, 10, 8, 18, 22, 1, 12, 2, 5, 1] Best cost: 5914.402 | Path: [1, 19, 3, 17, 21, 1, 7, 13, 15, 6, 23, 1, 8, 18, 10, 22, 4, 1, 2, 12, 5, 1] Best cost: 5873.467 | Path: [1, 19, 3, 17, 6, 1, 7, 13, 15, 21, 23, 1, 4, 22, 10, 8, 18, 1, 12, 2, 5, 1] Best cost: 5741.179 | Path: [1, 18, 8, 10, 22, 4, 1, 7, 13, 15, 6, 23, 1, 3, 19, 17, 21, 1, 12, 2, 5, 1] Best cost: 5728.898 | Path: [1, 3, 19, 17, 21, 1, 7, 13, 15, 6, 23, 1, 4, 22, 10, 8, 18, 1, 12, 2, 5, 1] Generation: #2 Best cost: 5660.745 | Path: [1, 21, 23, 6, 15, 1, 7, 13, 17, 19, 3, 1, 4, 22, 10, 8, 18, 1, 12, 2, 5, 1] OPTIMIZING each tour... Current: [[1, 21, 23, 6, 15, 1], [1, 7, 13, 17, 19, 3, 1], [1, 4, 22, 10, 8, 18, 1], [1, 12, 2, 5, 1]] [1] Cost: 1851.208 to 1849.647 | Optimized: [1, 15, 6, 23, 21, 1] [2] Cost: 1423.403 to 1421.450 | Optimized: [1, 3, 19, 17, 13, 7, 1] ACO RESULTS [1/300 vol./1849.647 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [2/280 vol./1421.450 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/300 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/205 vol./1272.297 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5657.231 km.