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: 14 customers
- Kassel-Wilhelmshöhe (25 vol.)
- Düsseldorf Hbf (20 vol.)
- Frankfurt Hbf (30 vol.)
- Aachen Hbf (40 vol.)
- Dresden Hbf (65 vol.)
- München Hbf (25 vol.)
- Leipzig Hbf (60 vol.)
- Karlsruhe Hbf (75 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (95 vol.)
- Würzburg Hbf (100 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (45 vol.)
Tour 1
COST: 1962.652 km
LOAD: 280 vol.
- München Hbf | 25 vol.
- Karlsruhe Hbf | 75 vol.
- Mannheim Hbf | 100 vol.
- Saarbrücken Hbf | 20 vol.
- Aachen Hbf | 40 vol.
- Düsseldorf Hbf | 20 vol.
Tour 2
COST: 1353.472 km
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 25 vol.
- Frankfurt Hbf | 30 vol.
- Würzburg Hbf | 100 vol.
- Leipzig Hbf | 60 vol.
- Dresden Hbf | 65 vol.
Tour 3
COST: 1441.221 km
LOAD: 195 vol.
- Köln Hbf | 55 vol.
- Osnabrück Hbf | 45 vol.
- Kiel Hbf | 95 vol.
LOAD: 280 vol.
- München Hbf | 25 vol.
- Karlsruhe Hbf | 75 vol.
- Mannheim Hbf | 100 vol.
- Saarbrücken Hbf | 20 vol.
- Aachen Hbf | 40 vol.
- Düsseldorf Hbf | 20 vol.
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 25 vol.
- Frankfurt Hbf | 30 vol.
- Würzburg Hbf | 100 vol.
- Leipzig Hbf | 60 vol.
- Dresden Hbf | 65 vol.
LOAD: 195 vol.
- Köln Hbf | 55 vol.
- Osnabrück Hbf | 45 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: 755 vol. | Vehicle capacity: 300 vol. Loads: [25, 0, 20, 30, 0, 40, 0, 65, 0, 25, 0, 60, 0, 0, 75, 0, 55, 100, 95, 0, 100, 20, 45, 0] ITERATION Generation: #1 Best cost: 5683.308 | Path: [1, 0, 22, 2, 16, 5, 3, 14, 1, 11, 7, 20, 9, 21, 1, 18, 17, 1] Best cost: 5321.496 | Path: [1, 2, 16, 5, 3, 17, 21, 0, 1, 7, 11, 20, 14, 1, 18, 22, 9, 1] Best cost: 5279.734 | Path: [1, 7, 11, 0, 2, 16, 5, 21, 1, 18, 22, 3, 17, 9, 1, 20, 14, 1] Best cost: 5020.916 | Path: [1, 17, 14, 3, 21, 5, 2, 1, 7, 11, 0, 20, 9, 1, 18, 22, 16, 1] Best cost: 4951.039 | Path: [1, 16, 2, 5, 3, 17, 21, 9, 1, 7, 11, 0, 22, 18, 1, 20, 14, 1] Best cost: 4847.079 | Path: [1, 3, 17, 14, 21, 5, 2, 1, 11, 7, 9, 20, 0, 1, 18, 22, 16, 1] Generation: #2 Best cost: 4807.729 | Path: [1, 9, 14, 17, 21, 5, 2, 1, 11, 7, 20, 3, 0, 1, 18, 22, 16, 1] OPTIMIZING each tour... Current: [[1, 9, 14, 17, 21, 5, 2, 1], [1, 11, 7, 20, 3, 0, 1], [1, 18, 22, 16, 1]] [2] Cost: 1390.871 to 1353.472 | Optimized: [1, 0, 3, 20, 11, 7, 1] [3] Cost: 1454.206 to 1441.221 | Optimized: [1, 16, 22, 18, 1] ACO RESULTS [1/280 vol./1962.652 km] Berlin Hbf -> München Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Düsseldorf Hbf --> Berlin Hbf [2/280 vol./1353.472 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/195 vol./1441.221 km] Berlin Hbf -> Köln Hbf -> Osnabrück Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4757.345 km.