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: 19 customers
- Kassel-Wilhelmshöhe (50 vol.)
- Düsseldorf Hbf (80 vol.)
- Hannover Hbf (60 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (20 vol.)
- Hamburg Hbf (45 vol.)
- München Hbf (50 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (80 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (75 vol.)
- Ulm Hbf (45 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (20 vol.)
- Saarbrücken Hbf (25 vol.)
- Osnabrück Hbf (95 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 2134.463 km
LOAD: 280 vol.
- Düsseldorf Hbf | 80 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 30 vol.
- Saarbrücken Hbf | 25 vol.
- Freiburg Hbf | 50 vol.
- Stuttgart Hbf | 20 vol.
- Mannheim Hbf | 25 vol.
- Mainz Hbf | 20 vol.
Tour 2
COST: 1575.304 km
LOAD: 300 vol.
- Leipzig Hbf | 80 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 50 vol.
Tour 3
COST: 972.057 km
LOAD: 275 vol.
- Hannover Hbf | 60 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 80 vol.
Tour 4
COST: 1031.849 km
LOAD: 180 vol.
- Dortmund Hbf | 85 vol.
- Osnabrück Hbf | 95 vol.
LOAD: 280 vol.
- Düsseldorf Hbf | 80 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 30 vol.
- Saarbrücken Hbf | 25 vol.
- Freiburg Hbf | 50 vol.
- Stuttgart Hbf | 20 vol.
- Mannheim Hbf | 25 vol.
- Mainz Hbf | 20 vol.
LOAD: 300 vol.
- Leipzig Hbf | 80 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 50 vol.
LOAD: 275 vol.
- Hannover Hbf | 60 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 80 vol.
LOAD: 180 vol.
- Dortmund Hbf | 85 vol.
- Osnabrück 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: 1035 vol. | Vehicle capacity: 300 vol. Loads: [50, 0, 80, 0, 60, 30, 20, 0, 45, 50, 90, 80, 85, 75, 0, 45, 30, 25, 80, 20, 0, 25, 95, 50] ITERATION Generation: #1 Best cost: 6213.368 | Path: [1, 0, 22, 10, 4, 1, 11, 13, 9, 15, 6, 17, 1, 8, 18, 12, 2, 1, 19, 21, 23, 5, 16, 1] Best cost: 6176.224 | Path: [1, 23, 19, 17, 6, 15, 9, 13, 1, 11, 0, 22, 4, 1, 8, 18, 10, 12, 1, 2, 16, 5, 21, 1] Best cost: 6130.783 | Path: [1, 19, 17, 21, 23, 6, 15, 9, 0, 1, 11, 4, 10, 8, 1, 13, 16, 2, 12, 5, 1, 18, 22, 1] Best cost: 6075.469 | Path: [1, 9, 15, 6, 17, 19, 21, 23, 16, 5, 1, 11, 0, 12, 2, 1, 4, 10, 8, 18, 1, 22, 13, 1] Best cost: 6003.271 | Path: [1, 19, 17, 21, 23, 6, 15, 9, 0, 1, 11, 13, 2, 16, 5, 1, 4, 10, 8, 18, 1, 22, 12, 1] Best cost: 5900.054 | Path: [1, 2, 16, 5, 19, 17, 21, 23, 6, 1, 11, 0, 22, 4, 1, 8, 18, 10, 12, 1, 9, 15, 13, 1] Generation: #5 Best cost: 5798.084 | Path: [1, 16, 2, 5, 19, 17, 21, 23, 6, 1, 11, 13, 9, 15, 0, 1, 8, 18, 10, 4, 1, 22, 12, 1] OPTIMIZING each tour... Current: [[1, 16, 2, 5, 19, 17, 21, 23, 6, 1], [1, 11, 13, 9, 15, 0, 1], [1, 8, 18, 10, 4, 1], [1, 22, 12, 1]] [1] Cost: 2192.362 to 2134.463 | Optimized: [1, 2, 16, 5, 21, 23, 6, 17, 19, 1] [3] Cost: 992.078 to 972.057 | Optimized: [1, 4, 10, 8, 18, 1] [4] Cost: 1038.340 to 1031.849 | Optimized: [1, 12, 22, 1] ACO RESULTS [1/280 vol./2134.463 km] Berlin Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Mainz Hbf --> Berlin Hbf [2/300 vol./1575.304 km] Berlin Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [3/275 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/180 vol./1031.849 km] Berlin Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5713.673 km.