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 (80 vol.)
- Düsseldorf Hbf (30 vol.)
- Frankfurt Hbf (80 vol.)
- Dresden Hbf (70 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (25 vol.)
- Leipzig Hbf (85 vol.)
- Dortmund Hbf (75 vol.)
- Karlsruhe Hbf (90 vol.)
- Ulm Hbf (60 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (80 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (55 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1428.538 km
LOAD: 290 vol.
- Würzburg Hbf | 55 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 30 vol.
- Dortmund Hbf | 75 vol.
- Osnabrück Hbf | 70 vol.
Tour 2
COST: 1233.762 km
LOAD: 270 vol.
- Dresden Hbf | 70 vol.
- Leipzig Hbf | 85 vol.
- Bremen Hbf | 25 vol.
- Kiel Hbf | 90 vol.
Tour 3
COST: 1204.533 km
LOAD: 255 vol.
- Kassel-Wilhelmshöhe | 80 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 80 vol.
Tour 4
COST: 1623.452 km
LOAD: 255 vol.
- Mannheim Hbf | 80 vol.
- Karlsruhe Hbf | 90 vol.
- Freiburg Hbf | 85 vol.
Tour 5
COST: 1346.514 km
LOAD: 155 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 60 vol.
LOAD: 290 vol.
- Würzburg Hbf | 55 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 30 vol.
- Dortmund Hbf | 75 vol.
- Osnabrück Hbf | 70 vol.
LOAD: 270 vol.
- Dresden Hbf | 70 vol.
- Leipzig Hbf | 85 vol.
- Bremen Hbf | 25 vol.
- Kiel Hbf | 90 vol.
LOAD: 255 vol.
- Kassel-Wilhelmshöhe | 80 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 80 vol.
LOAD: 255 vol.
- Mannheim Hbf | 80 vol.
- Karlsruhe Hbf | 90 vol.
- Freiburg Hbf | 85 vol.
LOAD: 155 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 60 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: 1225 vol. | Vehicle capacity: 300 vol. Loads: [80, 0, 30, 80, 0, 0, 0, 70, 0, 95, 25, 85, 75, 0, 90, 60, 60, 80, 90, 95, 55, 0, 70, 85] ITERATION Generation: #1 Best cost: 7865.287 | Path: [1, 0, 12, 16, 2, 10, 1, 7, 11, 20, 3, 1, 22, 18, 19, 1, 15, 14, 17, 1, 9, 23, 1] Best cost: 7762.864 | Path: [1, 2, 16, 12, 0, 20, 1, 11, 7, 3, 15, 1, 18, 10, 22, 17, 1, 19, 14, 23, 1, 9, 1] Best cost: 7460.471 | Path: [1, 3, 19, 17, 2, 1, 11, 7, 20, 0, 1, 18, 10, 22, 12, 1, 9, 15, 14, 1, 16, 23, 1] Best cost: 7380.613 | Path: [1, 9, 15, 14, 20, 1, 11, 7, 0, 16, 1, 18, 10, 22, 12, 2, 1, 3, 19, 17, 1, 23, 1] Best cost: 7305.814 | Path: [1, 18, 10, 22, 12, 2, 1, 11, 7, 3, 20, 1, 16, 19, 17, 15, 1, 0, 14, 23, 1, 9, 1] Best cost: 7202.839 | Path: [1, 19, 3, 17, 2, 1, 11, 7, 0, 16, 1, 20, 14, 23, 15, 1, 18, 10, 22, 12, 1, 9, 1] Best cost: 7136.427 | Path: [1, 2, 16, 12, 22, 10, 1, 7, 11, 0, 20, 1, 18, 3, 19, 1, 23, 14, 17, 1, 9, 15, 1] Best cost: 7000.904 | Path: [1, 18, 10, 22, 12, 2, 1, 7, 11, 0, 16, 1, 3, 19, 17, 1, 20, 14, 23, 15, 1, 9, 1] Best cost: 6842.264 | Path: [1, 22, 12, 2, 16, 20, 1, 7, 11, 10, 18, 1, 0, 3, 19, 1, 17, 14, 23, 1, 9, 15, 1] OPTIMIZING each tour... Current: [[1, 22, 12, 2, 16, 20, 1], [1, 7, 11, 10, 18, 1], [1, 0, 3, 19, 1], [1, 17, 14, 23, 1], [1, 9, 15, 1]] [1] Cost: 1432.889 to 1428.538 | Optimized: [1, 20, 16, 2, 12, 22, 1] [3] Cost: 1205.647 to 1204.533 | Optimized: [1, 0, 19, 3, 1] ACO RESULTS [1/290 vol./1428.538 km] Berlin Hbf -> Würzburg Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Berlin Hbf [2/270 vol./1233.762 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [3/255 vol./1204.533 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [4/255 vol./1623.452 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [5/155 vol./1346.514 km] Berlin Hbf -> München Hbf -> Ulm Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6836.799 km.