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 (70 vol.)
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (40 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (20 vol.)
- Hamburg Hbf (75 vol.)
- München Hbf (75 vol.)
- Leipzig Hbf (65 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (45 vol.)
- Köln Hbf (80 vol.)
- Mannheim Hbf (50 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (80 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (35 vol.)
Tour 1
COST: 1667.474 km
LOAD: 300 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 80 vol.
- Mannheim Hbf | 50 vol.
- Saarbrücken Hbf | 35 vol.
- Stuttgart Hbf | 50 vol.
- Nürnberg Hbf | 45 vol.
Tour 2
COST: 1676.007 km
LOAD: 285 vol.
- Hannover Hbf | 40 vol.
- Würzburg Hbf | 85 vol.
- München Hbf | 75 vol.
- Leipzig Hbf | 65 vol.
- Dresden Hbf | 20 vol.
Tour 3
COST: 1231.292 km
LOAD: 275 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 70 vol.
Tour 4
COST: 732.557 km
LOAD: 125 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 50 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 80 vol.
- Mannheim Hbf | 50 vol.
- Saarbrücken Hbf | 35 vol.
- Stuttgart Hbf | 50 vol.
- Nürnberg Hbf | 45 vol.
LOAD: 285 vol.
- Hannover Hbf | 40 vol.
- Würzburg Hbf | 85 vol.
- München Hbf | 75 vol.
- Leipzig Hbf | 65 vol.
- Dresden Hbf | 20 vol.
LOAD: 275 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 80 vol.
- Kassel-Wilhelmshöhe | 70 vol.
LOAD: 125 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 50 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: 985 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 40, 40, 40, 0, 50, 20, 75, 75, 0, 65, 85, 45, 0, 0, 80, 50, 50, 80, 85, 35, 0, 0] ITERATION Generation: #1 Best cost: 6256.120 | Path: [1, 0, 19, 3, 17, 21, 7, 1, 11, 4, 8, 18, 2, 1, 9, 13, 20, 6, 1, 12, 16, 1] Best cost: 6062.015 | Path: [1, 3, 19, 17, 6, 13, 7, 1, 11, 0, 12, 2, 21, 1, 8, 18, 4, 16, 1, 20, 9, 1] Best cost: 5973.743 | Path: [1, 11, 7, 20, 3, 19, 1, 8, 18, 4, 0, 2, 1, 13, 9, 6, 17, 21, 1, 16, 12, 1] Best cost: 5962.062 | Path: [1, 19, 3, 17, 6, 21, 2, 1, 11, 7, 9, 13, 20, 1, 8, 18, 4, 12, 1, 0, 16, 1] Best cost: 5908.452 | Path: [1, 21, 17, 19, 3, 20, 1, 11, 7, 13, 9, 6, 2, 1, 8, 18, 4, 0, 1, 12, 16, 1] Best cost: 5770.544 | Path: [1, 3, 19, 17, 21, 6, 13, 1, 11, 7, 0, 4, 8, 1, 18, 2, 16, 12, 1, 9, 20, 1] Best cost: 5768.264 | Path: [1, 3, 19, 17, 21, 6, 13, 1, 11, 7, 0, 4, 8, 1, 18, 12, 2, 16, 1, 20, 9, 1] Best cost: 5344.969 | Path: [1, 3, 19, 17, 21, 6, 13, 1, 11, 7, 9, 20, 4, 1, 16, 2, 12, 0, 1, 18, 8, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 17, 21, 6, 13, 1], [1, 11, 7, 9, 20, 4, 1], [1, 16, 2, 12, 0, 1], [1, 18, 8, 1]] [2] Cost: 1701.147 to 1676.007 | Optimized: [1, 4, 20, 9, 11, 7, 1] [3] Cost: 1235.389 to 1231.292 | Optimized: [1, 12, 2, 16, 0, 1] [4] Cost: 740.959 to 732.557 | Optimized: [1, 8, 18, 1] ACO RESULTS [1/300 vol./1667.474 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Stuttgart Hbf -> Nürnberg Hbf --> Berlin Hbf [2/285 vol./1676.007 km] Berlin Hbf -> Hannover Hbf -> Würzburg Hbf -> München Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/275 vol./1231.292 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/125 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5307.330 km.