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 (85 vol.)
- Düsseldorf Hbf (75 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (50 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (30 vol.)
- Leipzig Hbf (25 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (90 vol.)
- Ulm Hbf (25 vol.)
- Köln Hbf (40 vol.)
- Mannheim Hbf (40 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (60 vol.)
- Würzburg Hbf (45 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (80 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1584.118 km
LOAD: 300 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 75 vol.
- Köln Hbf | 40 vol.
- Aachen Hbf | 80 vol.
- Mannheim Hbf | 40 vol.
Tour 2
COST: 1296.123 km
LOAD: 295 vol.
- Leipzig Hbf | 25 vol.
- Würzburg Hbf | 45 vol.
- Frankfurt Hbf | 80 vol.
- Mainz Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 85 vol.
Tour 3
COST: 1975.538 km
LOAD: 295 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 25 vol.
- Stuttgart Hbf | 50 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 20 vol.
Tour 4
COST: 936.176 km
LOAD: 220 vol.
- Hannover Hbf | 50 vol.
- Osnabrück Hbf | 80 vol.
- Hamburg Hbf | 90 vol.
Tour 5
COST: 701.943 km
LOAD: 95 vol.
- Kiel Hbf | 95 vol.
LOAD: 300 vol.
- Dortmund Hbf | 65 vol.
- Düsseldorf Hbf | 75 vol.
- Köln Hbf | 40 vol.
- Aachen Hbf | 80 vol.
- Mannheim Hbf | 40 vol.
LOAD: 295 vol.
- Leipzig Hbf | 25 vol.
- Würzburg Hbf | 45 vol.
- Frankfurt Hbf | 80 vol.
- Mainz Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 85 vol.
LOAD: 295 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 25 vol.
- Stuttgart Hbf | 50 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 20 vol.
LOAD: 220 vol.
- Hannover Hbf | 50 vol.
- Osnabrück Hbf | 80 vol.
- Hamburg Hbf | 90 vol.
LOAD: 95 vol.
- Kiel Hbf | 95 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: 1205 vol. | Vehicle capacity: 300 vol. Loads: [85, 0, 75, 80, 50, 80, 50, 0, 90, 30, 0, 25, 65, 90, 0, 25, 40, 40, 95, 60, 45, 20, 80, 80] ITERATION Generation: #1 Best cost: 8219.061 | Path: [1, 0, 22, 12, 16, 21, 1, 11, 13, 20, 3, 19, 1, 8, 18, 4, 17, 15, 1, 9, 6, 23, 5, 1, 2, 1] Best cost: 7748.275 | Path: [1, 3, 19, 17, 21, 6, 15, 11, 1, 8, 18, 4, 12, 1, 0, 22, 5, 16, 1, 13, 20, 9, 23, 1, 2, 1] Best cost: 7597.515 | Path: [1, 8, 18, 4, 12, 1, 11, 0, 20, 3, 19, 1, 13, 9, 15, 6, 17, 21, 16, 1, 22, 2, 5, 1, 23, 1] Best cost: 7569.729 | Path: [1, 18, 8, 22, 11, 1, 4, 0, 3, 19, 21, 1, 12, 2, 16, 5, 17, 1, 13, 20, 6, 15, 9, 1, 23, 1] Best cost: 7534.897 | Path: [1, 19, 3, 17, 21, 23, 1, 11, 20, 13, 15, 6, 9, 1, 8, 18, 4, 12, 1, 0, 22, 2, 16, 1, 5, 1] Best cost: 6821.007 | Path: [1, 21, 17, 3, 19, 16, 20, 1, 11, 13, 9, 15, 6, 23, 1, 22, 12, 2, 5, 1, 4, 8, 18, 1, 0, 1] Best cost: 6688.778 | Path: [1, 2, 16, 5, 12, 17, 1, 11, 0, 3, 19, 20, 1, 13, 9, 15, 6, 23, 21, 1, 4, 22, 8, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 2, 16, 5, 12, 17, 1], [1, 11, 0, 3, 19, 20, 1], [1, 13, 9, 15, 6, 23, 21, 1], [1, 4, 22, 8, 1], [1, 18, 1]] [1] Cost: 1747.594 to 1584.118 | Optimized: [1, 12, 2, 16, 5, 17, 1] [2] Cost: 1327.527 to 1296.123 | Optimized: [1, 11, 20, 3, 19, 0, 1] ACO RESULTS [1/300 vol./1584.118 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Mannheim Hbf --> Berlin Hbf [2/295 vol./1296.123 km] Berlin Hbf -> Leipzig Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Mainz Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [3/295 vol./1975.538 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [4/220 vol./ 936.176 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Hamburg Hbf --> Berlin Hbf [5/ 95 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6493.898 km.