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 (45 vol.)
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (85 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (90 vol.)
- Dresden Hbf (65 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (85 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (40 vol.)
- Nürnberg Hbf (35 vol.)
- Karlsruhe Hbf (50 vol.)
- Köln Hbf (80 vol.)
- Mannheim Hbf (55 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (100 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1211.245 km
LOAD: 270 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 85 vol.
- Würzburg Hbf | 85 vol.
Tour 2
COST: 1712.783 km
LOAD: 290 vol.
- München Hbf | 100 vol.
- Karlsruhe Hbf | 50 vol.
- Nürnberg Hbf | 35 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 65 vol.
Tour 3
COST: 1354.834 km
LOAD: 285 vol.
- Köln Hbf | 80 vol.
- Aachen Hbf | 40 vol.
- Düsseldorf Hbf | 80 vol.
- Dortmund Hbf | 40 vol.
- Kassel-Wilhelmshöhe | 45 vol.
Tour 4
COST: 1095.698 km
LOAD: 265 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 85 vol.
- Kiel Hbf | 80 vol.
Tour 5
COST: 1799.609 km
LOAD: 285 vol.
- Mannheim Hbf | 55 vol.
- Saarbrücken Hbf | 50 vol.
- Freiburg Hbf | 90 vol.
- Stuttgart Hbf | 90 vol.
LOAD: 270 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 85 vol.
- Würzburg Hbf | 85 vol.
LOAD: 290 vol.
- München Hbf | 100 vol.
- Karlsruhe Hbf | 50 vol.
- Nürnberg Hbf | 35 vol.
- Leipzig Hbf | 40 vol.
- Dresden Hbf | 65 vol.
LOAD: 285 vol.
- Köln Hbf | 80 vol.
- Aachen Hbf | 40 vol.
- Düsseldorf Hbf | 80 vol.
- Dortmund Hbf | 40 vol.
- Kassel-Wilhelmshöhe | 45 vol.
LOAD: 265 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 85 vol.
- Kiel Hbf | 80 vol.
LOAD: 285 vol.
- Mannheim Hbf | 55 vol.
- Saarbrücken Hbf | 50 vol.
- Freiburg Hbf | 90 vol.
- Stuttgart Hbf | 90 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: 1395 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 80, 85, 0, 40, 90, 65, 0, 100, 85, 40, 40, 35, 50, 0, 80, 55, 80, 100, 85, 50, 100, 90] ITERATION Generation: #1 Best cost: 7442.637 | Path: [1, 0, 12, 2, 16, 5, 1, 7, 11, 13, 20, 17, 1, 18, 10, 22, 1, 19, 3, 14, 21, 1, 6, 23, 9, 1] Best cost: 7325.743 | Path: [1, 3, 19, 17, 14, 1, 11, 7, 13, 20, 0, 1, 18, 10, 22, 1, 12, 2, 16, 5, 21, 1, 9, 6, 23, 1] Best cost: 7310.785 | Path: [1, 21, 17, 14, 6, 13, 1, 11, 7, 20, 3, 1, 18, 10, 22, 1, 0, 12, 2, 16, 5, 1, 19, 23, 9, 1] Best cost: 7309.205 | Path: [1, 21, 17, 14, 6, 13, 1, 11, 7, 19, 3, 1, 18, 10, 22, 1, 0, 12, 2, 16, 5, 1, 20, 23, 9, 1] Best cost: 7214.706 | Path: [1, 20, 3, 19, 1, 7, 11, 13, 6, 14, 1, 18, 10, 22, 1, 0, 12, 2, 16, 5, 1, 17, 21, 23, 9, 1] Generation: #4 Best cost: 7208.509 | Path: [1, 20, 3, 19, 1, 7, 11, 13, 9, 14, 1, 0, 12, 2, 16, 5, 1, 18, 10, 22, 1, 17, 21, 23, 6, 1] OPTIMIZING each tour... Current: [[1, 20, 3, 19, 1], [1, 7, 11, 13, 9, 14, 1], [1, 0, 12, 2, 16, 5, 1], [1, 18, 10, 22, 1], [1, 17, 21, 23, 6, 1]] [1] Cost: 1215.072 to 1211.245 | Optimized: [1, 19, 3, 20, 1] [2] Cost: 1719.910 to 1712.783 | Optimized: [1, 9, 14, 13, 11, 7, 1] [3] Cost: 1372.044 to 1354.834 | Optimized: [1, 16, 5, 2, 12, 0, 1] [4] Cost: 1101.874 to 1095.698 | Optimized: [1, 22, 10, 18, 1] ACO RESULTS [1/270 vol./1211.245 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf --> Berlin Hbf [2/290 vol./1712.783 km] Berlin Hbf -> München Hbf -> Karlsruhe Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/285 vol./1354.834 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/265 vol./1095.698 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [5/285 vol./1799.609 km] Berlin Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Stuttgart Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7174.169 km.