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: 16 customers
- Kassel-Wilhelmshöhe (100 vol.)
- Frankfurt Hbf (95 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (55 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (25 vol.)
- München Hbf (85 vol.)
- Leipzig Hbf (95 vol.)
- Dortmund Hbf (80 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (35 vol.)
- Ulm Hbf (40 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (100 vol.)
- Saarbrücken Hbf (65 vol.)
Tour 1
COST: 1290.503 km
LOAD: 295 vol.
- Mannheim Hbf | 100 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 95 vol.
Tour 2
COST: 975.554 km
LOAD: 285 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 100 vol.
Tour 3
COST: 1935.926 km
LOAD: 280 vol.
- Saarbrücken Hbf | 65 vol.
- Aachen Hbf | 75 vol.
- Dortmund Hbf | 80 vol.
- Hamburg Hbf | 25 vol.
- Kiel Hbf | 35 vol.
Tour 4
COST: 1582.686 km
LOAD: 275 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 55 vol.
- Karlsruhe Hbf | 35 vol.
- Nürnberg Hbf | 60 vol.
LOAD: 295 vol.
- Mannheim Hbf | 100 vol.
- Mainz Hbf | 100 vol.
- Frankfurt Hbf | 95 vol.
LOAD: 285 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 100 vol.
LOAD: 280 vol.
- Saarbrücken Hbf | 65 vol.
- Aachen Hbf | 75 vol.
- Dortmund Hbf | 80 vol.
- Hamburg Hbf | 25 vol.
- Kiel Hbf | 35 vol.
LOAD: 275 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 55 vol.
- Karlsruhe Hbf | 35 vol.
- Nürnberg 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: 1135 vol. | Vehicle capacity: 300 vol. Loads: [100, 0, 0, 95, 0, 75, 55, 90, 25, 85, 0, 95, 80, 60, 35, 40, 0, 100, 35, 100, 0, 65, 0, 0] ITERATION Generation: #1 Best cost: 6967.421 | Path: [1, 0, 12, 5, 14, 1, 11, 7, 13, 6, 1, 8, 18, 17, 3, 15, 1, 19, 21, 9, 1] Best cost: 6291.049 | Path: [1, 3, 19, 17, 1, 7, 11, 13, 6, 1, 8, 18, 12, 5, 21, 1, 0, 14, 15, 9, 1] Best cost: 5832.658 | Path: [1, 7, 11, 0, 1, 8, 18, 12, 5, 21, 1, 13, 9, 15, 6, 14, 1, 19, 3, 17, 1] Best cost: 5829.128 | Path: [1, 18, 8, 12, 5, 21, 1, 7, 11, 0, 1, 19, 3, 17, 1, 13, 9, 15, 6, 14, 1] Best cost: 5810.232 | Path: [1, 3, 19, 17, 1, 7, 11, 0, 1, 8, 18, 12, 5, 21, 1, 13, 9, 15, 6, 14, 1] Generation: #2 Best cost: 5810.232 | Path: [1, 7, 11, 0, 1, 8, 18, 12, 5, 21, 1, 13, 9, 15, 6, 14, 1, 3, 19, 17, 1] Best cost: 5799.876 | Path: [1, 17, 19, 3, 1, 7, 11, 0, 1, 8, 18, 12, 5, 21, 1, 9, 15, 6, 14, 13, 1] OPTIMIZING each tour... Current: [[1, 17, 19, 3, 1], [1, 7, 11, 0, 1], [1, 8, 18, 12, 5, 21, 1], [1, 9, 15, 6, 14, 13, 1]] [3] Cost: 1951.133 to 1935.926 | Optimized: [1, 21, 5, 12, 8, 18, 1] ACO RESULTS [1/295 vol./1290.503 km] Berlin Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/285 vol./ 975.554 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [3/280 vol./1935.926 km] Berlin Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Dortmund Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/275 vol./1582.686 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5784.669 km.