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: 19 customers
- Kassel-Wilhelmshöhe (50 vol.)
- Düsseldorf Hbf (85 vol.)
- Frankfurt Hbf (85 vol.)
- Hannover Hbf (45 vol.)
- Stuttgart Hbf (75 vol.)
- Dresden Hbf (50 vol.)
- Hamburg Hbf (25 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (45 vol.)
- Nürnberg Hbf (70 vol.)
- Karlsruhe Hbf (85 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (25 vol.)
- Mainz Hbf (70 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (75 vol.)
- Osnabrück Hbf (100 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1520.307 km
LOAD: 290 vol.
- Würzburg Hbf | 25 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 85 vol.
- Stuttgart Hbf | 75 vol.
- Ulm Hbf | 80 vol.
Tour 2
COST: 1098.074 km
LOAD: 265 vol.
- Dresden Hbf | 50 vol.
- Leipzig Hbf | 45 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 25 vol.
Tour 3
COST: 1747.015 km
LOAD: 300 vol.
- Frankfurt Hbf | 85 vol.
- Mainz Hbf | 70 vol.
- Saarbrücken Hbf | 75 vol.
- Freiburg Hbf | 70 vol.
Tour 4
COST: 1275.253 km
LOAD: 290 vol.
- Osnabrück Hbf | 100 vol.
- Düsseldorf Hbf | 85 vol.
- Köln Hbf | 55 vol.
- Kassel-Wilhelmshöhe | 50 vol.
Tour 5
COST: 869.684 km
LOAD: 70 vol.
- Nürnberg Hbf | 70 vol.
LOAD: 290 vol.
- Würzburg Hbf | 25 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 85 vol.
- Stuttgart Hbf | 75 vol.
- Ulm Hbf | 80 vol.
LOAD: 265 vol.
- Dresden Hbf | 50 vol.
- Leipzig Hbf | 45 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 25 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 85 vol.
- Mainz Hbf | 70 vol.
- Saarbrücken Hbf | 75 vol.
- Freiburg Hbf | 70 vol.
LOAD: 290 vol.
- Osnabrück Hbf | 100 vol.
- Düsseldorf Hbf | 85 vol.
- Köln Hbf | 55 vol.
- Kassel-Wilhelmshöhe | 50 vol.
LOAD: 70 vol.
- Nürnberg Hbf | 70 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: 1215 vol. | Vehicle capacity: 300 vol. Loads: [50, 0, 85, 85, 45, 0, 75, 50, 25, 0, 100, 45, 0, 70, 85, 80, 55, 25, 0, 70, 25, 75, 100, 70] ITERATION Generation: #1 Best cost: 8175.376 | Path: [1, 0, 20, 13, 3, 19, 1, 11, 7, 4, 10, 8, 17, 1, 22, 16, 2, 1, 6, 14, 21, 1, 15, 23, 1] Best cost: 7330.262 | Path: [1, 2, 16, 19, 3, 1, 7, 11, 13, 20, 6, 17, 1, 8, 10, 22, 4, 1, 0, 14, 15, 23, 1, 21, 1] Best cost: 7314.644 | Path: [1, 11, 7, 13, 20, 3, 17, 1, 8, 4, 10, 22, 1, 0, 16, 2, 19, 1, 15, 6, 14, 1, 21, 23, 1] Best cost: 7296.096 | Path: [1, 14, 17, 19, 3, 20, 1, 7, 11, 4, 10, 8, 1, 0, 22, 2, 16, 1, 13, 6, 15, 21, 1, 23, 1] Best cost: 7217.718 | Path: [1, 15, 6, 14, 17, 20, 1, 7, 11, 4, 8, 10, 1, 22, 2, 16, 0, 1, 13, 3, 19, 21, 1, 23, 1] Best cost: 7175.190 | Path: [1, 19, 3, 17, 14, 20, 1, 11, 7, 13, 15, 0, 1, 8, 10, 22, 4, 1, 6, 21, 23, 16, 1, 2, 1] Best cost: 6912.292 | Path: [1, 6, 14, 17, 19, 20, 1, 11, 7, 4, 10, 8, 1, 22, 16, 2, 0, 1, 13, 15, 23, 21, 1, 3, 1] Best cost: 6648.421 | Path: [1, 17, 14, 6, 15, 20, 1, 7, 11, 0, 22, 4, 1, 8, 10, 16, 2, 1, 3, 19, 21, 23, 1, 13, 1] Best cost: 6596.887 | Path: [1, 15, 6, 14, 17, 20, 1, 7, 11, 4, 10, 8, 1, 3, 19, 21, 23, 1, 0, 22, 2, 16, 1, 13, 1] OPTIMIZING each tour... Current: [[1, 15, 6, 14, 17, 20, 1], [1, 7, 11, 4, 10, 8, 1], [1, 3, 19, 21, 23, 1], [1, 0, 22, 2, 16, 1], [1, 13, 1]] [1] Cost: 1520.745 to 1520.307 | Optimized: [1, 20, 17, 14, 6, 15, 1] [4] Cost: 1361.369 to 1275.253 | Optimized: [1, 22, 2, 16, 0, 1] ACO RESULTS [1/290 vol./1520.307 km] Berlin Hbf -> Würzburg Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [2/265 vol./1098.074 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/300 vol./1747.015 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf --> Berlin Hbf [4/290 vol./1275.253 km] Berlin Hbf -> Osnabrück Hbf -> Düsseldorf Hbf -> Köln Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [5/ 70 vol./ 869.684 km] Berlin Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6510.333 km.