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: 400 vol.
ACTIVE: 18 customers
- Berlin Hbf (95 vol.)
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (85 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (70 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (55 vol.)
- Dortmund Hbf (75 vol.)
- Nürnberg Hbf (45 vol.)
- Mannheim Hbf (60 vol.)
- Kiel Hbf (75 vol.)
- Würzburg Hbf (25 vol.)
- Osnabrück Hbf (40 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1138.301 km
LOAD: 400 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 45 vol.
- Dortmund Hbf | 75 vol.
- Düsseldorf Hbf | 65 vol.
- Aachen Hbf | 85 vol.
- Frankfurt Hbf | 90 vol.
Tour 2
COST: 1389.885 km
LOAD: 375 vol.
- Würzburg Hbf | 25 vol.
- Nürnberg Hbf | 45 vol.
- München Hbf | 70 vol.
- Stuttgart Hbf | 95 vol.
- Freiburg Hbf | 80 vol.
- Mannheim Hbf | 60 vol.
Tour 3
COST: 1356.365 km
LOAD: 400 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 75 vol.
- Berlin Hbf | 95 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 55 vol.
Tour 4
COST: 362.286 km
LOAD: 40 vol.
- Hannover Hbf | 40 vol.
LOAD: 400 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 45 vol.
- Dortmund Hbf | 75 vol.
- Düsseldorf Hbf | 65 vol.
- Aachen Hbf | 85 vol.
- Frankfurt Hbf | 90 vol.
LOAD: 375 vol.
- Würzburg Hbf | 25 vol.
- Nürnberg Hbf | 45 vol.
- München Hbf | 70 vol.
- Stuttgart Hbf | 95 vol.
- Freiburg Hbf | 80 vol.
- Mannheim Hbf | 60 vol.
LOAD: 400 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 75 vol.
- Berlin Hbf | 95 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 55 vol.
LOAD: 40 vol.
- Hannover Hbf | 40 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1215 vol. | Vehicle capacity: 400 vol. Loads: [0, 95, 65, 90, 40, 85, 95, 75, 100, 70, 45, 55, 75, 45, 0, 0, 0, 60, 75, 0, 25, 0, 40, 80] ITERATION Generation: #1 Best cost: 5345.854 | Path: [0, 1, 11, 7, 13, 20, 3, 0, 12, 2, 5, 17, 6, 0, 22, 10, 8, 18, 4, 23, 0, 9, 0] Best cost: 4748.192 | Path: [0, 3, 17, 6, 20, 13, 9, 0, 12, 2, 5, 22, 4, 10, 0, 11, 7, 1, 18, 8, 0, 23, 0] Best cost: 4643.803 | Path: [0, 17, 3, 20, 13, 9, 6, 0, 12, 2, 5, 22, 10, 4, 0, 11, 7, 1, 8, 18, 0, 23, 0] Best cost: 4638.097 | Path: [0, 10, 22, 12, 2, 5, 3, 0, 20, 13, 9, 6, 17, 23, 0, 4, 8, 18, 1, 11, 0, 7, 0] Best cost: 4620.772 | Path: [0, 17, 3, 20, 13, 9, 6, 0, 12, 2, 5, 22, 10, 4, 0, 11, 7, 1, 18, 8, 0, 23, 0] Best cost: 4563.989 | Path: [0, 3, 17, 6, 13, 9, 20, 0, 12, 2, 5, 22, 10, 4, 0, 8, 18, 1, 7, 11, 0, 23, 0] Best cost: 4538.581 | Path: [0, 4, 22, 12, 2, 5, 3, 0, 20, 13, 9, 6, 17, 23, 0, 11, 7, 1, 8, 18, 0, 10, 0] Best cost: 4436.332 | Path: [0, 20, 13, 9, 6, 17, 3, 0, 12, 2, 5, 22, 10, 4, 0, 11, 7, 1, 8, 18, 0, 23, 0] Generation: #2 Best cost: 4408.762 | Path: [0, 10, 22, 12, 2, 5, 3, 0, 20, 13, 9, 6, 17, 23, 0, 11, 7, 1, 8, 18, 0, 4, 0] OPTIMIZING each tour... Current: [[0, 10, 22, 12, 2, 5, 3, 0], [0, 20, 13, 9, 6, 17, 23, 0], [0, 11, 7, 1, 8, 18, 0], [0, 4, 0]] [1] Cost: 1156.638 to 1138.301 | Optimized: [0, 22, 10, 12, 2, 5, 3, 0] [2] Cost: 1498.905 to 1389.885 | Optimized: [0, 20, 13, 9, 6, 23, 17, 0] [3] Cost: 1390.933 to 1356.365 | Optimized: [0, 8, 18, 1, 7, 11, 0] ACO RESULTS [1/400 vol./1138.301 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [2/375 vol./1389.885 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Mannheim Hbf --> Kassel-Wilhelmshöhe [3/400 vol./1356.365 km] Kassel-Wilhelmshöhe -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [4/ 40 vol./ 362.286 km] Kassel-Wilhelmshöhe -> Hannover Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4246.837 km.