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: 18 customers
- Kassel-Wilhelmshöhe (45 vol.)
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (30 vol.)
- Dresden Hbf (50 vol.)
- Hamburg Hbf (45 vol.)
- München Hbf (50 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (55 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (55 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (70 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (20 vol.)
- Saarbrücken Hbf (55 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1748.474 km
LOAD: 265 vol.
- Würzburg Hbf | 20 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 55 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 30 vol.
Tour 2
COST: 1520.359 km
LOAD: 280 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 70 vol.
- Nürnberg Hbf | 55 vol.
- Leipzig Hbf | 55 vol.
- Dresden Hbf | 50 vol.
Tour 3
COST: 1309.409 km
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Dortmund Hbf | 50 vol.
- Düsseldorf Hbf | 80 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 55 vol.
Tour 4
COST: 732.557 km
LOAD: 140 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 95 vol.
LOAD: 265 vol.
- Würzburg Hbf | 20 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 55 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 30 vol.
LOAD: 280 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 70 vol.
- Nürnberg Hbf | 55 vol.
- Leipzig Hbf | 55 vol.
- Dresden Hbf | 50 vol.
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Dortmund Hbf | 50 vol.
- Düsseldorf Hbf | 80 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 55 vol.
LOAD: 140 vol.
- Hamburg 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: 965 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 80, 30, 0, 0, 0, 50, 45, 50, 55, 55, 50, 55, 100, 70, 0, 0, 95, 25, 20, 55, 50, 35] ITERATION Generation: #1 Best cost: 6791.352 | Path: [1, 0, 3, 19, 20, 13, 9, 15, 1, 7, 11, 8, 18, 10, 1, 2, 12, 22, 21, 23, 1, 14, 1] Best cost: 6543.100 | Path: [1, 3, 19, 21, 14, 15, 20, 1, 7, 11, 0, 22, 12, 8, 1, 18, 10, 2, 23, 1, 13, 9, 1] Best cost: 6324.293 | Path: [1, 7, 11, 0, 12, 2, 20, 1, 8, 18, 10, 22, 3, 19, 1, 15, 14, 23, 21, 1, 9, 13, 1] Best cost: 6312.273 | Path: [1, 8, 18, 10, 22, 12, 1, 7, 11, 13, 20, 3, 19, 21, 1, 0, 2, 14, 23, 1, 9, 15, 1] Best cost: 6253.862 | Path: [1, 13, 20, 19, 3, 14, 23, 1, 11, 7, 9, 15, 21, 1, 8, 18, 10, 22, 12, 1, 0, 2, 1] Best cost: 5932.298 | Path: [1, 20, 3, 19, 21, 14, 23, 1, 11, 7, 13, 15, 9, 1, 8, 18, 10, 22, 12, 1, 0, 2, 1] Best cost: 5863.365 | Path: [1, 14, 23, 21, 19, 3, 20, 1, 11, 7, 13, 9, 15, 1, 8, 18, 10, 22, 12, 1, 0, 2, 1] Best cost: 5742.110 | Path: [1, 3, 19, 14, 23, 21, 20, 1, 7, 11, 13, 9, 15, 1, 0, 22, 10, 8, 18, 1, 2, 12, 1] Best cost: 5586.902 | Path: [1, 14, 23, 21, 19, 3, 20, 1, 7, 11, 13, 9, 15, 1, 22, 12, 2, 0, 10, 1, 8, 18, 1] Generation: #2 Best cost: 5408.779 | Path: [1, 14, 23, 21, 19, 3, 20, 1, 11, 7, 13, 9, 15, 1, 0, 2, 12, 22, 10, 1, 8, 18, 1] Generation: #5 Best cost: 5401.189 | Path: [1, 14, 23, 21, 19, 3, 20, 1, 11, 7, 13, 9, 15, 1, 0, 12, 2, 22, 10, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 14, 23, 21, 19, 3, 20, 1], [1, 11, 7, 13, 9, 15, 1], [1, 0, 12, 2, 22, 10, 1], [1, 8, 18, 1]] [1] Cost: 1805.515 to 1748.474 | Optimized: [1, 20, 14, 23, 21, 19, 3, 1] [2] Cost: 1553.708 to 1520.359 | Optimized: [1, 9, 15, 13, 11, 7, 1] ACO RESULTS [1/265 vol./1748.474 km] Berlin Hbf -> Würzburg Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/280 vol./1520.359 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/280 vol./1309.409 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Bremen Hbf --> Berlin Hbf [4/140 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5310.799 km.