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 (95 vol.)
- Düsseldorf Hbf (85 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (50 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (70 vol.)
- Nürnberg Hbf (30 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (35 vol.)
- Köln Hbf (50 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (35 vol.)
- Saarbrücken Hbf (25 vol.)
- Osnabrück Hbf (45 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1223.889 km
LOAD: 300 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 85 vol.
- Köln Hbf | 50 vol.
- Osnabrück Hbf | 45 vol.
- Hannover Hbf | 50 vol.
Tour 2
COST: 1868.043 km
LOAD: 300 vol.
- Würzburg Hbf | 35 vol.
- Mainz Hbf | 35 vol.
- Saarbrücken Hbf | 25 vol.
- Ulm Hbf | 35 vol.
- München Hbf | 100 vol.
- Nürnberg Hbf | 30 vol.
- Leipzig Hbf | 40 vol.
Tour 3
COST: 1664.709 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Frankfurt Hbf | 30 vol.
- Karlsruhe Hbf | 95 vol.
- Freiburg Hbf | 80 vol.
Tour 4
COST: 781.807 km
LOAD: 95 vol.
- Bremen Hbf | 95 vol.
LOAD: 300 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 85 vol.
- Köln Hbf | 50 vol.
- Osnabrück Hbf | 45 vol.
- Hannover Hbf | 50 vol.
LOAD: 300 vol.
- Würzburg Hbf | 35 vol.
- Mainz Hbf | 35 vol.
- Saarbrücken Hbf | 25 vol.
- Ulm Hbf | 35 vol.
- München Hbf | 100 vol.
- Nürnberg Hbf | 30 vol.
- Leipzig Hbf | 40 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Frankfurt Hbf | 30 vol.
- Karlsruhe Hbf | 95 vol.
- Freiburg Hbf | 80 vol.
LOAD: 95 vol.
- Bremen 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: 995 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 85, 30, 50, 0, 0, 0, 0, 100, 95, 40, 70, 30, 95, 35, 50, 0, 0, 35, 35, 25, 45, 80] ITERATION Generation: #1 Best cost: 6112.424 | Path: [1, 0, 12, 2, 16, 1, 11, 4, 10, 22, 3, 19, 1, 13, 20, 15, 14, 21, 23, 1, 9, 1] Best cost: 6027.136 | Path: [1, 3, 19, 21, 14, 23, 15, 1, 11, 20, 13, 9, 4, 22, 1, 10, 12, 2, 16, 1, 0, 1] Best cost: 5994.082 | Path: [1, 12, 2, 16, 19, 3, 21, 1, 11, 13, 20, 14, 23, 1, 0, 22, 4, 10, 1, 9, 15, 1] Best cost: 5982.916 | Path: [1, 0, 20, 3, 19, 21, 23, 1, 11, 4, 10, 22, 12, 1, 13, 9, 15, 14, 1, 2, 16, 1] Best cost: 5964.381 | Path: [1, 14, 15, 9, 13, 20, 1, 11, 3, 19, 21, 23, 12, 1, 4, 10, 22, 0, 1, 16, 2, 1] Best cost: 5631.312 | Path: [1, 16, 2, 12, 22, 4, 1, 11, 20, 13, 9, 15, 21, 19, 1, 0, 3, 14, 23, 1, 10, 1] OPTIMIZING each tour... Current: [[1, 16, 2, 12, 22, 4, 1], [1, 11, 20, 13, 9, 15, 21, 19, 1], [1, 0, 3, 14, 23, 1], [1, 10, 1]] [1] Cost: 1227.003 to 1223.889 | Optimized: [1, 12, 2, 16, 22, 4, 1] [2] Cost: 1957.793 to 1868.043 | Optimized: [1, 20, 19, 21, 15, 9, 13, 11, 1] ACO RESULTS [1/300 vol./1223.889 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [2/300 vol./1868.043 km] Berlin Hbf -> Würzburg Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Ulm Hbf -> München Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [3/300 vol./1664.709 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [4/ 95 vol./ 781.807 km] Berlin Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5538.448 km.