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: 20 customers
- Kassel-Wilhelmshöhe (60 vol.)
- Düsseldorf Hbf (75 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (80 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (40 vol.)
- Dresden Hbf (20 vol.)
- München Hbf (55 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (30 vol.)
- Ulm Hbf (100 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (85 vol.)
- Mainz Hbf (85 vol.)
- Würzburg Hbf (55 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (35 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 1544.628 km
LOAD: 300 vol.
- Dresden Hbf | 20 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 40 vol.
- Würzburg Hbf | 55 vol.
Tour 2
COST: 1097.862 km
LOAD: 250 vol.
- Leipzig Hbf | 80 vol.
- Hannover Hbf | 80 vol.
- Osnabrück Hbf | 35 vol.
- Bremen Hbf | 55 vol.
Tour 3
COST: 1336.583 km
LOAD: 290 vol.
- Mannheim Hbf | 85 vol.
- Mainz Hbf | 85 vol.
- Frankfurt Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 60 vol.
Tour 4
COST: 1291.407 km
LOAD: 275 vol.
- Köln Hbf | 65 vol.
- Aachen Hbf | 75 vol.
- Düsseldorf Hbf | 75 vol.
- Dortmund Hbf | 60 vol.
Tour 5
COST: 1733.565 km
LOAD: 125 vol.
- Saarbrücken Hbf | 70 vol.
- Freiburg Hbf | 55 vol.
LOAD: 300 vol.
- Dresden Hbf | 20 vol.
- Nürnberg Hbf | 30 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 40 vol.
- Würzburg Hbf | 55 vol.
LOAD: 250 vol.
- Leipzig Hbf | 80 vol.
- Hannover Hbf | 80 vol.
- Osnabrück Hbf | 35 vol.
- Bremen Hbf | 55 vol.
LOAD: 290 vol.
- Mannheim Hbf | 85 vol.
- Mainz Hbf | 85 vol.
- Frankfurt Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 60 vol.
LOAD: 275 vol.
- Köln Hbf | 65 vol.
- Aachen Hbf | 75 vol.
- Düsseldorf Hbf | 75 vol.
- Dortmund Hbf | 60 vol.
LOAD: 125 vol.
- Saarbrücken Hbf | 70 vol.
- Freiburg Hbf | 55 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: 1240 vol. | Vehicle capacity: 300 vol. Loads: [60, 0, 75, 60, 80, 75, 40, 20, 0, 55, 55, 80, 60, 30, 0, 100, 65, 85, 0, 85, 55, 70, 35, 55] ITERATION Generation: #1 Best cost: 7460.866 | Path: [1, 0, 12, 2, 16, 22, 1, 11, 7, 13, 9, 15, 1, 4, 10, 5, 19, 1, 3, 17, 21, 23, 1, 20, 6, 1] Best cost: 7352.015 | Path: [1, 22, 12, 2, 16, 3, 1, 11, 7, 0, 4, 10, 1, 13, 20, 6, 15, 9, 1, 19, 17, 21, 23, 1, 5, 1] Best cost: 7231.969 | Path: [1, 6, 15, 9, 13, 20, 7, 1, 11, 4, 10, 22, 1, 2, 16, 5, 12, 1, 0, 3, 19, 17, 1, 21, 23, 1] Best cost: 7182.950 | Path: [1, 20, 13, 9, 15, 6, 7, 1, 11, 4, 22, 10, 1, 12, 2, 16, 5, 1, 0, 3, 19, 17, 1, 23, 21, 1] Generation: #3 Best cost: 7141.128 | Path: [1, 9, 15, 6, 20, 13, 7, 1, 11, 4, 10, 22, 1, 0, 12, 2, 16, 1, 21, 23, 17, 3, 1, 19, 5, 1] Generation: #5 Best cost: 7069.248 | Path: [1, 9, 15, 6, 20, 13, 7, 1, 11, 4, 10, 22, 1, 0, 3, 19, 17, 1, 16, 5, 2, 12, 1, 23, 21, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 20, 13, 7, 1], [1, 11, 4, 10, 22, 1], [1, 0, 3, 19, 17, 1], [1, 16, 5, 2, 12, 1], [1, 23, 21, 1]] [1] Cost: 1589.128 to 1544.628 | Optimized: [1, 7, 13, 9, 15, 6, 20, 1] [2] Cost: 1113.505 to 1097.862 | Optimized: [1, 11, 4, 22, 10, 1] [3] Cost: 1338.208 to 1336.583 | Optimized: [1, 17, 19, 3, 0, 1] [5] Cost: 1737.000 to 1733.565 | Optimized: [1, 21, 23, 1] ACO RESULTS [1/300 vol./1544.628 km] Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [2/250 vol./1097.862 km] Berlin Hbf -> Leipzig Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf --> Berlin Hbf [3/290 vol./1336.583 km] Berlin Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/275 vol./1291.407 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf [5/125 vol./1733.565 km] Berlin Hbf -> Saarbrücken Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7004.045 km.