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 (70 vol.)
- Düsseldorf Hbf (30 vol.)
- Frankfurt Hbf (20 vol.)
- Stuttgart Hbf (100 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (75 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (90 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (70 vol.)
- Ulm Hbf (60 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (65 vol.)
- Würzburg Hbf (20 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (40 vol.)
Tour 1
COST: 1560.937 km
LOAD: 285 vol.
- Würzburg Hbf | 20 vol.
- Frankfurt Hbf | 20 vol.
- Mainz Hbf | 65 vol.
- Düsseldorf Hbf | 30 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 65 vol.
Tour 2
COST: 1392.837 km
LOAD: 250 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 60 vol.
- Nürnberg Hbf | 25 vol.
- Leipzig Hbf | 90 vol.
Tour 3
COST: 1619.773 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Saarbrücken Hbf | 60 vol.
- Karlsruhe Hbf | 70 vol.
- Stuttgart Hbf | 100 vol.
Tour 4
COST: 701.943 km
LOAD: 90 vol.
- Kiel Hbf | 90 vol.
LOAD: 285 vol.
- Würzburg Hbf | 20 vol.
- Frankfurt Hbf | 20 vol.
- Mainz Hbf | 65 vol.
- Düsseldorf Hbf | 30 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 65 vol.
LOAD: 250 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 60 vol.
- Nürnberg Hbf | 25 vol.
- Leipzig Hbf | 90 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 70 vol.
- Saarbrücken Hbf | 60 vol.
- Karlsruhe Hbf | 70 vol.
- Stuttgart Hbf | 100 vol.
LOAD: 90 vol.
- Kiel Hbf | 90 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: 925 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 30, 20, 0, 0, 100, 0, 65, 75, 45, 90, 0, 25, 70, 60, 0, 0, 90, 65, 20, 60, 40, 0] ITERATION Generation: #1 Best cost: 7077.520 | Path: [1, 0, 22, 10, 8, 13, 20, 3, 1, 11, 6, 14, 2, 1, 18, 19, 21, 15, 1, 9, 1] Best cost: 6660.525 | Path: [1, 2, 22, 10, 8, 18, 20, 1, 11, 0, 19, 3, 13, 1, 9, 15, 6, 21, 1, 14, 1] Best cost: 6456.843 | Path: [1, 3, 19, 6, 14, 20, 13, 1, 11, 0, 22, 10, 2, 1, 8, 18, 21, 15, 1, 9, 1] Best cost: 6156.108 | Path: [1, 8, 18, 10, 22, 2, 3, 1, 11, 0, 20, 13, 9, 1, 19, 14, 6, 15, 1, 21, 1] Best cost: 5545.583 | Path: [1, 9, 15, 6, 19, 1, 11, 13, 20, 3, 14, 21, 1, 8, 18, 10, 22, 2, 1, 0, 1] Best cost: 5436.555 | Path: [1, 3, 19, 21, 14, 15, 20, 1, 11, 13, 9, 6, 1, 8, 18, 10, 22, 2, 1, 0, 1] Best cost: 5364.614 | Path: [1, 20, 3, 19, 2, 22, 10, 8, 1, 11, 13, 9, 15, 1, 0, 6, 14, 21, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 20, 3, 19, 2, 22, 10, 8, 1], [1, 11, 13, 9, 15, 1], [1, 0, 6, 14, 21, 1], [1, 18, 1]] [2] Cost: 1401.293 to 1392.837 | Optimized: [1, 9, 15, 13, 11, 1] [3] Cost: 1700.441 to 1619.773 | Optimized: [1, 0, 21, 14, 6, 1] ACO RESULTS [1/285 vol./1560.937 km] Berlin Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Mainz Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [2/250 vol./1392.837 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [3/300 vol./1619.773 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Saarbrücken Hbf -> Karlsruhe Hbf -> Stuttgart Hbf --> Berlin Hbf [4/ 90 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5275.490 km.