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 (95 vol.)
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (55 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (25 vol.)
- München Hbf (55 vol.)
- Bremen Hbf (80 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (60 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (90 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (35 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (40 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (45 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1445.155 km
LOAD: 280 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 40 vol.
- Mannheim Hbf | 35 vol.
- Karlsruhe Hbf | 95 vol.
- Stuttgart Hbf | 50 vol.
- Würzburg Hbf | 30 vol.
Tour 2
COST: 1264.264 km
LOAD: 280 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 80 vol.
- Hannover Hbf | 25 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 25 vol.
- Kiel Hbf | 25 vol.
Tour 3
COST: 1370.534 km
LOAD: 280 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 55 vol.
- Kassel-Wilhelmshöhe | 95 vol.
Tour 4
COST: 2074.001 km
LOAD: 295 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 90 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 60 vol.
- Osnabrück Hbf | 45 vol.
LOAD: 280 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 40 vol.
- Mannheim Hbf | 35 vol.
- Karlsruhe Hbf | 95 vol.
- Stuttgart Hbf | 50 vol.
- Würzburg Hbf | 30 vol.
LOAD: 280 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 80 vol.
- Hannover Hbf | 25 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 25 vol.
- Kiel Hbf | 25 vol.
LOAD: 280 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 55 vol.
- Kassel-Wilhelmshöhe | 95 vol.
LOAD: 295 vol.
- München Hbf | 55 vol.
- Ulm Hbf | 90 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 60 vol.
- Osnabrück 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: 1135 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 40, 30, 25, 55, 50, 45, 25, 55, 80, 80, 60, 0, 95, 90, 30, 35, 25, 40, 30, 60, 45, 45] ITERATION Generation: #1 Best cost: 6936.429 | Path: [1, 0, 12, 2, 16, 5, 1, 7, 11, 4, 10, 22, 8, 1, 18, 20, 3, 19, 17, 14, 23, 1, 6, 15, 9, 21, 1] Best cost: 6887.011 | Path: [1, 3, 19, 17, 14, 6, 20, 1, 11, 7, 4, 10, 22, 8, 1, 0, 12, 2, 16, 5, 1, 18, 15, 9, 23, 21, 1] Best cost: 6670.854 | Path: [1, 4, 10, 8, 18, 22, 12, 2, 1, 7, 11, 9, 15, 20, 1, 0, 3, 19, 17, 14, 1, 16, 5, 21, 23, 6, 1] Best cost: 6592.931 | Path: [1, 6, 14, 17, 3, 19, 20, 1, 7, 11, 4, 10, 22, 8, 1, 0, 12, 2, 16, 5, 1, 18, 21, 23, 15, 9, 1] Best cost: 6557.981 | Path: [1, 7, 11, 4, 10, 8, 18, 1, 0, 22, 12, 2, 16, 3, 1, 15, 6, 14, 17, 20, 1, 5, 19, 21, 23, 9, 1] Best cost: 6479.750 | Path: [1, 12, 2, 16, 5, 19, 3, 20, 1, 11, 7, 4, 10, 8, 18, 1, 22, 0, 17, 14, 1, 9, 15, 6, 23, 21, 1] Best cost: 6429.471 | Path: [1, 19, 3, 17, 14, 6, 20, 1, 11, 7, 4, 8, 18, 10, 1, 0, 12, 2, 16, 5, 1, 9, 15, 23, 21, 22, 1] Best cost: 6387.745 | Path: [1, 9, 15, 6, 14, 1, 7, 11, 4, 8, 18, 10, 1, 0, 12, 2, 16, 5, 1, 22, 3, 19, 17, 21, 23, 20, 1] Best cost: 6339.909 | Path: [1, 14, 6, 15, 9, 1, 7, 11, 4, 10, 8, 18, 1, 22, 12, 2, 16, 5, 19, 3, 1, 0, 20, 17, 21, 23, 1] Best cost: 6324.695 | Path: [1, 6, 14, 17, 19, 3, 20, 1, 11, 7, 4, 10, 8, 18, 1, 0, 2, 5, 16, 12, 1, 22, 21, 23, 15, 9, 1] Best cost: 6277.991 | Path: [1, 3, 19, 17, 14, 6, 20, 1, 11, 7, 4, 10, 8, 18, 1, 0, 12, 2, 16, 5, 1, 22, 21, 23, 15, 9, 1] Best cost: 6261.748 | Path: [1, 20, 19, 3, 17, 14, 6, 1, 7, 11, 4, 10, 8, 18, 1, 0, 12, 2, 16, 5, 1, 22, 21, 23, 15, 9, 1] Best cost: 6201.221 | Path: [1, 0, 12, 2, 16, 5, 1, 7, 11, 4, 10, 8, 18, 1, 19, 3, 17, 14, 6, 20, 1, 22, 21, 23, 15, 9, 1] Generation: #2 Best cost: 6178.795 | Path: [1, 0, 12, 2, 16, 5, 1, 7, 11, 4, 10, 8, 18, 1, 3, 19, 17, 14, 6, 20, 1, 22, 21, 23, 15, 9, 1] Best cost: 6178.795 | Path: [1, 3, 19, 17, 14, 6, 20, 1, 7, 11, 4, 10, 8, 18, 1, 0, 12, 2, 16, 5, 1, 22, 21, 23, 15, 9, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 17, 14, 6, 20, 1], [1, 7, 11, 4, 10, 8, 18, 1], [1, 0, 12, 2, 16, 5, 1], [1, 22, 21, 23, 15, 9, 1]] [3] Cost: 1372.044 to 1370.534 | Optimized: [1, 12, 2, 16, 5, 0, 1] [4] Cost: 2097.332 to 2074.001 | Optimized: [1, 9, 15, 23, 21, 22, 1] ACO RESULTS [1/280 vol./1445.155 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [2/280 vol./1264.264 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/280 vol./1370.534 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/295 vol./2074.001 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Osnabrück Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6153.954 km.