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 (85 vol.)
- Düsseldorf Hbf (45 vol.)
- Frankfurt Hbf (20 vol.)
- Hannover Hbf (20 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (65 vol.)
- Hamburg Hbf (45 vol.)
- München Hbf (75 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (50 vol.)
- Nürnberg Hbf (90 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (70 vol.)
- Köln Hbf (90 vol.)
- Mannheim Hbf (25 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (95 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1672.847 km
LOAD: 295 vol.
- Frankfurt Hbf | 20 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 45 vol.
- Würzburg Hbf | 95 vol.
Tour 2
COST: 1168.259 km
LOAD: 275 vol.
- Hamburg Hbf | 45 vol.
- Bremen Hbf | 55 vol.
- Osnabrück Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 85 vol.
- Hannover Hbf | 20 vol.
Tour 3
COST: 1392.837 km
LOAD: 285 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 70 vol.
- Nürnberg Hbf | 90 vol.
- Leipzig Hbf | 50 vol.
Tour 4
COST: 1714.046 km
LOAD: 245 vol.
- Stuttgart Hbf | 65 vol.
- Aachen Hbf | 45 vol.
- Köln Hbf | 90 vol.
- Düsseldorf Hbf | 45 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 20 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 45 vol.
- Würzburg Hbf | 95 vol.
LOAD: 275 vol.
- Hamburg Hbf | 45 vol.
- Bremen Hbf | 55 vol.
- Osnabrück Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 85 vol.
- Hannover Hbf | 20 vol.
LOAD: 285 vol.
- München Hbf | 75 vol.
- Ulm Hbf | 70 vol.
- Nürnberg Hbf | 90 vol.
- Leipzig Hbf | 50 vol.
LOAD: 245 vol.
- Stuttgart Hbf | 65 vol.
- Aachen Hbf | 45 vol.
- Köln Hbf | 90 vol.
- Düsseldorf Hbf | 45 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: 1100 vol. | Vehicle capacity: 300 vol. Loads: [85, 0, 45, 20, 20, 45, 65, 0, 45, 75, 55, 50, 0, 90, 55, 70, 90, 25, 0, 55, 95, 0, 70, 45] ITERATION Generation: #1 Best cost: 7088.144 | Path: [1, 0, 22, 10, 4, 8, 3, 1, 11, 13, 20, 19, 1, 2, 16, 5, 17, 14, 1, 6, 15, 9, 23, 1] Best cost: 6721.917 | Path: [1, 2, 16, 5, 19, 3, 17, 4, 1, 11, 13, 20, 6, 1, 8, 10, 22, 0, 23, 1, 15, 14, 9, 1] Best cost: 6334.472 | Path: [1, 3, 19, 17, 14, 6, 15, 1, 11, 4, 10, 22, 0, 1, 8, 5, 2, 16, 23, 1, 13, 20, 9, 1] Best cost: 6282.517 | Path: [1, 6, 14, 17, 19, 3, 2, 4, 1, 11, 0, 22, 10, 1, 8, 5, 16, 20, 1, 13, 9, 15, 23, 1] Best cost: 6110.348 | Path: [1, 23, 14, 17, 19, 3, 20, 1, 11, 0, 22, 10, 4, 1, 8, 2, 16, 5, 6, 1, 13, 15, 9, 1] Best cost: 6033.748 | Path: [1, 20, 3, 19, 17, 14, 23, 1, 11, 13, 9, 15, 1, 4, 0, 22, 10, 8, 1, 16, 2, 5, 6, 1] Generation: #2 Best cost: 6024.840 | Path: [1, 23, 14, 17, 19, 3, 20, 1, 8, 10, 22, 0, 4, 1, 11, 13, 9, 15, 1, 2, 16, 5, 6, 1] OPTIMIZING each tour... Current: [[1, 23, 14, 17, 19, 3, 20, 1], [1, 8, 10, 22, 0, 4, 1], [1, 11, 13, 9, 15, 1], [1, 2, 16, 5, 6, 1]] [1] Cost: 1732.852 to 1672.847 | Optimized: [1, 3, 19, 17, 14, 23, 20, 1] [3] Cost: 1401.293 to 1392.837 | Optimized: [1, 9, 15, 13, 11, 1] [4] Cost: 1722.436 to 1714.046 | Optimized: [1, 6, 5, 16, 2, 1] ACO RESULTS [1/295 vol./1672.847 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [2/275 vol./1168.259 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Osnabrück Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf --> Berlin Hbf [3/285 vol./1392.837 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [4/245 vol./1714.046 km] Berlin Hbf -> Stuttgart Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5947.989 km.