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
- Kassel-Wilhelmshöhe (60 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (25 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (30 vol.)
- Dresden Hbf (80 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (35 vol.)
- Karlsruhe Hbf (75 vol.)
- Köln Hbf (40 vol.)
- Kiel Hbf (60 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (75 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1664.455 km
LOAD: 290 vol.
- Frankfurt Hbf | 25 vol.
- Saarbrücken Hbf | 50 vol.
- Aachen Hbf | 30 vol.
- Köln Hbf | 40 vol.
- Düsseldorf Hbf | 90 vol.
- Dortmund Hbf | 55 vol.
Tour 2
COST: 1179.657 km
LOAD: 290 vol.
- Dresden Hbf | 80 vol.
- Leipzig Hbf | 20 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Osnabrück Hbf | 75 vol.
- Hannover Hbf | 55 vol.
Tour 3
COST: 1674.877 km
LOAD: 285 vol.
- Karlsruhe Hbf | 75 vol.
- Freiburg Hbf | 80 vol.
- Würzburg Hbf | 95 vol.
- Nürnberg Hbf | 35 vol.
Tour 4
COST: 944.451 km
LOAD: 160 vol.
- Kiel Hbf | 60 vol.
- Bremen Hbf | 100 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 25 vol.
- Saarbrücken Hbf | 50 vol.
- Aachen Hbf | 30 vol.
- Köln Hbf | 40 vol.
- Düsseldorf Hbf | 90 vol.
- Dortmund Hbf | 55 vol.
LOAD: 290 vol.
- Dresden Hbf | 80 vol.
- Leipzig Hbf | 20 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Osnabrück Hbf | 75 vol.
- Hannover Hbf | 55 vol.
LOAD: 285 vol.
- Karlsruhe Hbf | 75 vol.
- Freiburg Hbf | 80 vol.
- Würzburg Hbf | 95 vol.
- Nürnberg Hbf | 35 vol.
LOAD: 160 vol.
- Kiel Hbf | 60 vol.
- Bremen Hbf | 100 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: 1025 vol. | Vehicle capacity: 300 vol. Loads: [60, 0, 90, 25, 55, 30, 0, 80, 0, 0, 100, 20, 55, 35, 75, 0, 40, 0, 60, 0, 95, 50, 75, 80] ITERATION Generation: #1 Best cost: 5980.889 | Path: [1, 0, 12, 2, 16, 5, 3, 1, 7, 11, 13, 20, 21, 1, 4, 22, 10, 18, 1, 14, 23, 1] Best cost: 5973.786 | Path: [1, 13, 20, 3, 14, 21, 11, 1, 7, 4, 10, 18, 1, 22, 12, 2, 16, 5, 1, 0, 23, 1] Best cost: 5939.049 | Path: [1, 2, 16, 5, 12, 22, 1, 11, 7, 13, 20, 3, 1, 4, 10, 18, 0, 1, 14, 23, 21, 1] Best cost: 5929.247 | Path: [1, 5, 16, 2, 12, 22, 1, 11, 7, 13, 20, 3, 1, 4, 10, 18, 0, 1, 21, 23, 14, 1] Best cost: 5921.774 | Path: [1, 23, 14, 21, 3, 13, 11, 1, 7, 0, 12, 2, 1, 18, 10, 22, 4, 1, 20, 16, 5, 1] Best cost: 5814.138 | Path: [1, 2, 16, 5, 12, 0, 11, 1, 7, 13, 20, 3, 21, 1, 4, 22, 10, 18, 1, 14, 23, 1] Best cost: 5783.894 | Path: [1, 16, 2, 5, 12, 22, 1, 11, 7, 13, 20, 3, 1, 18, 10, 4, 0, 1, 14, 23, 21, 1] Best cost: 5732.410 | Path: [1, 12, 2, 16, 5, 21, 3, 1, 11, 7, 13, 20, 0, 1, 18, 10, 22, 4, 1, 14, 23, 1] Best cost: 5695.570 | Path: [1, 14, 21, 23, 3, 13, 11, 1, 7, 4, 10, 18, 1, 22, 12, 2, 16, 5, 1, 0, 20, 1] Best cost: 5678.682 | Path: [1, 11, 7, 0, 3, 20, 1, 4, 22, 10, 18, 1, 13, 14, 23, 21, 5, 1, 2, 16, 12, 1] Best cost: 5470.439 | Path: [1, 12, 2, 16, 5, 21, 3, 1, 7, 11, 0, 22, 4, 1, 13, 20, 14, 23, 1, 18, 10, 1] OPTIMIZING each tour... Current: [[1, 12, 2, 16, 5, 21, 3, 1], [1, 7, 11, 0, 22, 4, 1], [1, 13, 20, 14, 23, 1], [1, 18, 10, 1]] [1] Cost: 1670.644 to 1664.455 | Optimized: [1, 3, 21, 5, 16, 2, 12, 1] [3] Cost: 1675.687 to 1674.877 | Optimized: [1, 14, 23, 20, 13, 1] ACO RESULTS [1/290 vol./1664.455 km] Berlin Hbf -> Frankfurt Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf [2/290 vol./1179.657 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [3/285 vol./1674.877 km] Berlin Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf [4/160 vol./ 944.451 km] Berlin Hbf -> Kiel Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5463.440 km.