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: 22 customers
- Kassel-Wilhelmshöhe (70 vol.)
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (20 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (25 vol.)
- München Hbf (55 vol.)
- Bremen Hbf (60 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (45 vol.)
- Köln Hbf (45 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (85 vol.)
- Mainz Hbf (60 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1672.847 km
LOAD: 290 vol.
- Frankfurt Hbf | 20 vol.
- Mainz Hbf | 60 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 50 vol.
- Würzburg Hbf | 80 vol.
Tour 2
COST: 2080.934 km
LOAD: 295 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 20 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 45 vol.
- Stuttgart Hbf | 20 vol.
- Saarbrücken Hbf | 70 vol.
- Osnabrück Hbf | 20 vol.
Tour 3
COST: 1370.534 km
LOAD: 250 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 45 vol.
- Aachen Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 70 vol.
Tour 4
COST: 959.922 km
LOAD: 230 vol.
- Hannover Hbf | 85 vol.
- Bremen Hbf | 60 vol.
- Kiel Hbf | 85 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 20 vol.
- Mainz Hbf | 60 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 50 vol.
- Würzburg Hbf | 80 vol.
LOAD: 295 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 20 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 45 vol.
- Stuttgart Hbf | 20 vol.
- Saarbrücken Hbf | 70 vol.
- Osnabrück Hbf | 20 vol.
LOAD: 250 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 45 vol.
- Aachen Hbf | 30 vol.
- Kassel-Wilhelmshöhe | 70 vol.
LOAD: 230 vol.
- Hannover Hbf | 85 vol.
- Bremen Hbf | 60 vol.
- Kiel Hbf | 85 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: 1065 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 40, 20, 85, 30, 20, 25, 0, 55, 60, 20, 65, 40, 55, 45, 45, 25, 85, 60, 80, 70, 20, 50] ITERATION Generation: #1 Best cost: 7729.647 | Path: [1, 0, 12, 2, 16, 5, 17, 3, 1, 11, 7, 20, 13, 15, 6, 14, 1, 4, 10, 22, 18, 23, 1, 19, 21, 9, 1] Best cost: 7125.640 | Path: [1, 3, 19, 17, 14, 6, 15, 9, 11, 1, 7, 20, 13, 0, 22, 12, 1, 4, 10, 18, 2, 5, 1, 16, 21, 23, 1] Best cost: 7097.880 | Path: [1, 9, 15, 6, 14, 17, 19, 3, 22, 1, 11, 7, 13, 20, 0, 12, 1, 4, 10, 18, 2, 5, 1, 16, 21, 23, 1] Best cost: 7076.471 | Path: [1, 10, 4, 0, 12, 22, 1, 11, 7, 13, 20, 3, 19, 17, 6, 1, 18, 2, 16, 5, 21, 1, 15, 9, 14, 23, 1] Best cost: 6700.033 | Path: [1, 13, 20, 3, 19, 17, 14, 6, 1, 7, 11, 4, 10, 22, 12, 1, 18, 0, 2, 16, 5, 1, 9, 15, 23, 21, 1] Best cost: 6693.294 | Path: [1, 21, 14, 6, 15, 9, 13, 1, 11, 7, 4, 22, 10, 18, 1, 0, 12, 2, 16, 5, 3, 17, 1, 20, 19, 23, 1] Best cost: 6632.640 | Path: [1, 18, 10, 4, 0, 1, 11, 7, 13, 20, 3, 19, 17, 6, 1, 22, 12, 2, 16, 5, 21, 1, 15, 14, 23, 9, 1] Best cost: 6503.035 | Path: [1, 9, 15, 6, 14, 17, 19, 3, 22, 1, 18, 10, 4, 0, 1, 11, 7, 20, 13, 23, 21, 1, 5, 16, 2, 12, 1] Best cost: 6451.796 | Path: [1, 20, 13, 6, 14, 17, 19, 3, 1, 7, 11, 0, 22, 10, 4, 1, 18, 2, 16, 5, 12, 1, 21, 23, 15, 9, 1] Best cost: 6428.939 | Path: [1, 3, 19, 17, 14, 6, 15, 9, 11, 1, 7, 13, 20, 0, 4, 1, 18, 10, 22, 12, 2, 5, 1, 16, 21, 23, 1] Best cost: 6290.503 | Path: [1, 9, 15, 6, 14, 17, 19, 3, 22, 1, 11, 7, 4, 10, 18, 1, 12, 2, 16, 5, 21, 23, 1, 0, 20, 13, 1] Generation: #2 Best cost: 6191.307 | Path: [1, 9, 15, 6, 14, 17, 19, 3, 22, 1, 7, 11, 4, 10, 18, 1, 12, 2, 16, 5, 21, 23, 1, 0, 20, 13, 1] Best cost: 6171.974 | Path: [1, 23, 14, 17, 19, 3, 20, 1, 11, 7, 13, 9, 15, 6, 21, 22, 1, 0, 12, 2, 16, 5, 1, 4, 10, 18, 1] OPTIMIZING each tour... Current: [[1, 23, 14, 17, 19, 3, 20, 1], [1, 11, 7, 13, 9, 15, 6, 21, 22, 1], [1, 0, 12, 2, 16, 5, 1], [1, 4, 10, 18, 1]] [1] Cost: 1732.852 to 1672.847 | Optimized: [1, 3, 19, 17, 14, 23, 20, 1] [2] Cost: 2107.156 to 2080.934 | Optimized: [1, 7, 11, 13, 9, 15, 6, 21, 22, 1] [3] Cost: 1372.044 to 1370.534 | Optimized: [1, 12, 2, 16, 5, 0, 1] ACO RESULTS [1/290 vol./1672.847 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [2/295 vol./2080.934 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Saarbrücken Hbf -> Osnabrück Hbf --> Berlin Hbf [3/250 vol./1370.534 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/230 vol./ 959.922 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6084.237 km.