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: 15 customers
- Kassel-Wilhelmshöhe (50 vol.)
- Düsseldorf Hbf (45 vol.)
- Aachen Hbf (90 vol.)
- Bremen Hbf (20 vol.)
- Leipzig Hbf (35 vol.)
- Nürnberg Hbf (95 vol.)
- Karlsruhe Hbf (70 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (80 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (70 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (20 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1875.053 km
LOAD: 285 vol.
- Ulm Hbf | 95 vol.
- Karlsruhe Hbf | 70 vol.
- Freiburg Hbf | 20 vol.
- Saarbrücken Hbf | 20 vol.
- Mannheim Hbf | 80 vol.
Tour 2
COST: 1346.287 km
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Mainz Hbf | 70 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 95 vol.
- Leipzig Hbf | 35 vol.
Tour 3
COST: 1578.851 km
LOAD: 290 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 90 vol.
- Düsseldorf Hbf | 45 vol.
- Bremen Hbf | 20 vol.
- Kiel Hbf | 100 vol.
LOAD: 285 vol.
- Ulm Hbf | 95 vol.
- Karlsruhe Hbf | 70 vol.
- Freiburg Hbf | 20 vol.
- Saarbrücken Hbf | 20 vol.
- Mannheim Hbf | 80 vol.
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Mainz Hbf | 70 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 95 vol.
- Leipzig Hbf | 35 vol.
LOAD: 290 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 90 vol.
- Düsseldorf Hbf | 45 vol.
- Bremen Hbf | 20 vol.
- Kiel 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: 865 vol. | Vehicle capacity: 300 vol. Loads: [50, 0, 45, 0, 0, 90, 0, 0, 0, 0, 20, 35, 0, 95, 70, 95, 35, 80, 100, 70, 40, 20, 0, 20] ITERATION Generation: #1 Best cost: 5328.784 | Path: [1, 0, 11, 13, 20, 19, 1, 18, 10, 2, 16, 5, 1, 17, 14, 23, 21, 15, 1] Best cost: 5197.715 | Path: [1, 15, 14, 17, 21, 23, 1, 11, 0, 13, 20, 19, 1, 18, 10, 2, 16, 5, 1] Best cost: 5146.465 | Path: [1, 17, 14, 23, 21, 19, 20, 1, 11, 13, 15, 0, 10, 1, 18, 2, 16, 5, 1] Best cost: 5055.414 | Path: [1, 18, 10, 16, 2, 5, 1, 11, 0, 19, 17, 21, 23, 1, 13, 20, 14, 15, 1] Best cost: 5002.325 | Path: [1, 18, 10, 2, 16, 5, 1, 11, 13, 20, 19, 21, 23, 1, 0, 17, 14, 15, 1] Best cost: 4973.105 | Path: [1, 17, 14, 15, 20, 1, 11, 0, 19, 21, 23, 13, 1, 18, 10, 2, 16, 5, 1] Best cost: 4967.666 | Path: [1, 15, 14, 17, 21, 23, 1, 11, 0, 19, 20, 13, 1, 18, 10, 2, 16, 5, 1] Best cost: 4956.528 | Path: [1, 15, 14, 17, 20, 1, 11, 0, 19, 21, 23, 13, 1, 18, 10, 2, 16, 5, 1] Generation: #2 Best cost: 4935.732 | Path: [1, 21, 17, 14, 23, 15, 1, 11, 0, 19, 20, 13, 1, 18, 10, 2, 16, 5, 1] OPTIMIZING each tour... Current: [[1, 21, 17, 14, 23, 15, 1], [1, 11, 0, 19, 20, 13, 1], [1, 18, 10, 2, 16, 5, 1]] [1] Cost: 1960.812 to 1875.053 | Optimized: [1, 15, 14, 23, 21, 17, 1] [2] Cost: 1375.538 to 1346.287 | Optimized: [1, 0, 19, 20, 13, 11, 1] [3] Cost: 1599.382 to 1578.851 | Optimized: [1, 16, 5, 2, 10, 18, 1] ACO RESULTS [1/285 vol./1875.053 km] Berlin Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mannheim Hbf --> Berlin Hbf [2/290 vol./1346.287 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Mainz Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [3/290 vol./1578.851 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4800.191 km.