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: 19 customers
- Berlin Hbf (25 vol.)
- Düsseldorf Hbf (30 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (45 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (70 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (35 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (80 vol.)
- Mannheim Hbf (45 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (35 vol.)
- Osnabrück Hbf (40 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1390.776 km
LOAD: 400 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 70 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 70 vol.
Tour 2
COST: 1573.619 km
LOAD: 375 vol.
- Osnabrück Hbf | 40 vol.
- Hannover Hbf | 25 vol.
- Bremen Hbf | 70 vol.
- Kiel Hbf | 70 vol.
- Berlin Hbf | 25 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 100 vol.
Tour 3
COST: 1026.07 km
LOAD: 245 vol.
- Dortmund Hbf | 35 vol.
- Düsseldorf Hbf | 30 vol.
- Aachen Hbf | 45 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 45 vol.
- Würzburg Hbf | 35 vol.
LOAD: 400 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 70 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 70 vol.
LOAD: 375 vol.
- Osnabrück Hbf | 40 vol.
- Hannover Hbf | 25 vol.
- Bremen Hbf | 70 vol.
- Kiel Hbf | 70 vol.
- Berlin Hbf | 25 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 100 vol.
LOAD: 245 vol.
- Dortmund Hbf | 35 vol.
- Düsseldorf Hbf | 30 vol.
- Aachen Hbf | 45 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 45 vol.
- Würzburg Hbf | 35 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: 1020 vol. | Vehicle capacity: 400 vol. Loads: [0, 25, 30, 0, 25, 45, 70, 45, 0, 80, 70, 100, 35, 60, 40, 80, 0, 45, 70, 55, 35, 0, 40, 70] ITERATION Generation: #1 Best cost: 5748.681 | Path: [0, 1, 11, 7, 13, 20, 6, 14, 4, 0, 12, 2, 5, 19, 17, 23, 15, 22, 0, 10, 18, 9, 0] Best cost: 5235.004 | Path: [0, 2, 5, 12, 22, 10, 4, 11, 7, 0, 19, 17, 14, 6, 15, 9, 1, 0, 20, 13, 23, 18, 0] Best cost: 4706.583 | Path: [0, 4, 22, 12, 2, 5, 19, 17, 14, 6, 0, 20, 13, 9, 15, 23, 10, 0, 11, 7, 1, 18, 0] Best cost: 4656.963 | Path: [0, 11, 7, 1, 4, 10, 22, 12, 2, 0, 20, 13, 9, 15, 6, 14, 0, 19, 17, 23, 5, 18, 0] Best cost: 4326.590 | Path: [0, 12, 2, 5, 19, 17, 14, 6, 15, 0, 22, 10, 4, 18, 1, 11, 7, 0, 20, 13, 9, 23, 0] Best cost: 4308.052 | Path: [0, 10, 4, 22, 12, 2, 5, 19, 17, 14, 0, 20, 13, 9, 15, 6, 23, 0, 11, 7, 1, 18, 0] Best cost: 4251.022 | Path: [0, 22, 10, 4, 12, 2, 5, 19, 17, 14, 0, 20, 13, 9, 15, 6, 23, 0, 11, 7, 1, 18, 0] Best cost: 4179.045 | Path: [0, 4, 10, 22, 12, 2, 5, 19, 17, 14, 0, 20, 13, 9, 15, 6, 23, 0, 11, 7, 1, 18, 0] Best cost: 4100.699 | Path: [0, 23, 14, 6, 15, 9, 13, 0, 22, 4, 10, 18, 1, 11, 7, 0, 12, 2, 5, 19, 17, 20, 0] Generation: #3 Best cost: 4028.408 | Path: [0, 23, 14, 6, 15, 9, 13, 0, 22, 10, 4, 18, 1, 7, 11, 0, 12, 2, 5, 19, 17, 20, 0] OPTIMIZING each tour... Current: [[0, 23, 14, 6, 15, 9, 13, 0], [0, 22, 10, 4, 18, 1, 7, 11, 0], [0, 12, 2, 5, 19, 17, 20, 0]] [1] Cost: 1405.998 to 1390.776 | Optimized: [0, 13, 9, 15, 6, 14, 23, 0] [2] Cost: 1596.340 to 1573.619 | Optimized: [0, 22, 4, 10, 18, 1, 7, 11, 0] ACO RESULTS [1/400 vol./1390.776 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [2/375 vol./1573.619 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Hannover Hbf -> Bremen Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/245 vol./1026.070 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Mainz Hbf -> Mannheim Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3990.465 km.