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
- Kassel-Wilhelmshöhe (35 vol.)
- Hannover Hbf (90 vol.)
- Stuttgart Hbf (70 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (25 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (45 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (20 vol.)
- Mannheim Hbf (30 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (50 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1974.677 km
LOAD: 295 vol.
- Köln Hbf | 20 vol.
- Mainz Hbf | 95 vol.
- Saarbrücken Hbf | 50 vol.
- Freiburg Hbf | 65 vol.
- Mannheim Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 35 vol.
Tour 2
COST: 1227.968 km
LOAD: 300 vol.
- Hamburg Hbf | 100 vol.
- Bremen Hbf | 25 vol.
- Hannover Hbf | 90 vol.
- Dortmund Hbf | 85 vol.
Tour 3
COST: 1445.778 km
LOAD: 275 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 70 vol.
- Würzburg Hbf | 85 vol.
Tour 4
COST: 869.684 km
LOAD: 45 vol.
- Nürnberg Hbf | 45 vol.
LOAD: 295 vol.
- Köln Hbf | 20 vol.
- Mainz Hbf | 95 vol.
- Saarbrücken Hbf | 50 vol.
- Freiburg Hbf | 65 vol.
- Mannheim Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 35 vol.
LOAD: 300 vol.
- Hamburg Hbf | 100 vol.
- Bremen Hbf | 25 vol.
- Hannover Hbf | 90 vol.
- Dortmund Hbf | 85 vol.
LOAD: 275 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 70 vol.
- Würzburg Hbf | 85 vol.
LOAD: 45 vol.
- Nürnberg Hbf | 45 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: 915 vol. | Vehicle capacity: 300 vol. Loads: [35, 0, 0, 0, 90, 0, 70, 0, 100, 40, 25, 0, 85, 45, 0, 80, 20, 30, 0, 95, 85, 50, 0, 65] ITERATION Generation: #1 Best cost: 6532.828 | Path: [1, 0, 12, 16, 19, 17, 10, 1, 4, 8, 20, 1, 13, 9, 15, 6, 23, 1, 21, 1] Best cost: 6430.987 | Path: [1, 8, 10, 4, 0, 17, 16, 1, 13, 20, 19, 21, 1, 12, 23, 6, 15, 1, 9, 1] Best cost: 6318.867 | Path: [1, 9, 15, 6, 17, 21, 16, 1, 8, 10, 4, 0, 13, 1, 12, 19, 20, 1, 23, 1] Best cost: 6249.255 | Path: [1, 15, 6, 20, 13, 16, 1, 4, 8, 10, 12, 1, 0, 19, 17, 21, 23, 1, 9, 1] Best cost: 6190.488 | Path: [1, 23, 21, 17, 19, 16, 0, 1, 4, 10, 8, 12, 1, 20, 13, 9, 15, 1, 6, 1] Best cost: 6184.494 | Path: [1, 4, 10, 8, 0, 16, 17, 1, 19, 21, 23, 6, 1, 13, 20, 15, 9, 1, 12, 1] Best cost: 6108.446 | Path: [1, 21, 19, 17, 15, 9, 1, 8, 10, 4, 0, 16, 1, 13, 20, 6, 23, 1, 12, 1] Best cost: 6096.565 | Path: [1, 17, 19, 21, 23, 13, 1, 8, 10, 4, 0, 16, 1, 15, 6, 20, 9, 1, 12, 1] Best cost: 6095.981 | Path: [1, 21, 19, 17, 20, 0, 1, 4, 10, 8, 12, 1, 13, 9, 15, 6, 23, 1, 16, 1] Best cost: 6067.767 | Path: [1, 6, 15, 9, 13, 17, 16, 1, 8, 10, 4, 12, 1, 0, 19, 21, 23, 1, 20, 1] Best cost: 6050.727 | Path: [1, 9, 15, 6, 17, 21, 16, 1, 8, 10, 4, 0, 13, 1, 20, 19, 23, 1, 12, 1] Best cost: 5853.225 | Path: [1, 23, 21, 17, 19, 16, 0, 1, 8, 10, 4, 12, 1, 13, 20, 6, 15, 1, 9, 1] Best cost: 5768.101 | Path: [1, 19, 17, 21, 23, 13, 1, 8, 10, 4, 0, 16, 1, 20, 6, 15, 9, 1, 12, 1] Generation: #2 Best cost: 5627.249 | Path: [1, 23, 6, 15, 9, 13, 1, 12, 16, 19, 17, 21, 1, 8, 10, 4, 0, 1, 20, 1] Generation: #4 Best cost: 5621.162 | Path: [1, 19, 17, 21, 23, 16, 0, 1, 8, 10, 4, 12, 1, 20, 6, 15, 9, 1, 13, 1] OPTIMIZING each tour... Current: [[1, 19, 17, 21, 23, 16, 0, 1], [1, 8, 10, 4, 12, 1], [1, 20, 6, 15, 9, 1], [1, 13, 1]] [1] Cost: 2065.243 to 1974.677 | Optimized: [1, 16, 19, 21, 23, 17, 0, 1] [3] Cost: 1458.267 to 1445.778 | Optimized: [1, 9, 15, 6, 20, 1] ACO RESULTS [1/295 vol./1974.677 km] Berlin Hbf -> Köln Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Mannheim Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [2/300 vol./1227.968 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Hannover Hbf -> Dortmund Hbf --> Berlin Hbf [3/275 vol./1445.778 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [4/ 45 vol./ 869.684 km] Berlin Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5518.107 km.