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: 20 customers
- Kassel-Wilhelmshöhe (45 vol.)
- Düsseldorf Hbf (70 vol.)
- Frankfurt Hbf (45 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (85 vol.)
- Dresden Hbf (40 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (30 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (95 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (55 vol.)
- Köln Hbf (20 vol.)
- Mannheim Hbf (80 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (85 vol.)
- Freiburg Hbf (30 vol.)
Tour 1
COST: 1327.422 km
LOAD: 300 vol.
- Leipzig Hbf | 35 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 30 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 65 vol.
Tour 2
COST: 1645.972 km
LOAD: 300 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 55 vol.
- Karlsruhe Hbf | 65 vol.
- Nürnberg Hbf | 100 vol.
- Dresden Hbf | 40 vol.
Tour 3
COST: 1952.632 km
LOAD: 295 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 70 vol.
- Aachen Hbf | 80 vol.
- Köln Hbf | 20 vol.
- Freiburg Hbf | 30 vol.
Tour 4
COST: 1430.8 km
LOAD: 295 vol.
- Stuttgart Hbf | 85 vol.
- Mannheim Hbf | 80 vol.
- Mainz Hbf | 85 vol.
- Frankfurt Hbf | 45 vol.
LOAD: 300 vol.
- Leipzig Hbf | 35 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 30 vol.
- Hamburg Hbf | 80 vol.
- Kiel Hbf | 65 vol.
LOAD: 300 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 55 vol.
- Karlsruhe Hbf | 65 vol.
- Nürnberg Hbf | 100 vol.
- Dresden Hbf | 40 vol.
LOAD: 295 vol.
- Dortmund Hbf | 95 vol.
- Düsseldorf Hbf | 70 vol.
- Aachen Hbf | 80 vol.
- Köln Hbf | 20 vol.
- Freiburg Hbf | 30 vol.
LOAD: 295 vol.
- Stuttgart Hbf | 85 vol.
- Mannheim Hbf | 80 vol.
- Mainz Hbf | 85 vol.
- Frankfurt 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: 1190 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 70, 45, 45, 80, 85, 40, 80, 40, 30, 35, 95, 100, 65, 55, 20, 80, 65, 85, 0, 0, 0, 30] ITERATION Generation: #1 Best cost: 7931.282 | Path: [1, 0, 12, 2, 16, 3, 1, 11, 7, 13, 15, 9, 23, 1, 8, 18, 10, 4, 5, 1, 19, 17, 14, 1, 6, 1] Best cost: 7680.417 | Path: [1, 2, 16, 5, 12, 10, 1, 11, 7, 13, 9, 15, 23, 1, 8, 18, 4, 0, 3, 1, 19, 17, 14, 1, 6, 1] Best cost: 7663.072 | Path: [1, 6, 14, 17, 3, 16, 1, 11, 7, 13, 15, 9, 23, 1, 4, 10, 8, 18, 0, 1, 12, 2, 5, 1, 19, 1] Best cost: 7565.400 | Path: [1, 7, 11, 0, 12, 2, 1, 8, 18, 4, 10, 16, 3, 1, 13, 9, 15, 6, 1, 19, 17, 14, 23, 1, 5, 1] Best cost: 7404.708 | Path: [1, 18, 8, 10, 4, 11, 7, 1, 13, 9, 15, 6, 16, 1, 0, 12, 2, 5, 1, 3, 19, 17, 14, 1, 23, 1] Best cost: 7331.977 | Path: [1, 6, 14, 17, 3, 16, 1, 11, 7, 13, 9, 15, 23, 1, 18, 8, 10, 4, 0, 1, 12, 2, 5, 1, 19, 1] Best cost: 7183.153 | Path: [1, 19, 3, 17, 14, 16, 1, 11, 7, 13, 9, 6, 1, 8, 18, 10, 4, 0, 23, 1, 12, 2, 5, 15, 1] Best cost: 7003.303 | Path: [1, 23, 14, 17, 19, 16, 1, 7, 11, 4, 10, 8, 18, 1, 0, 12, 2, 5, 1, 13, 9, 15, 6, 1, 3, 1] Best cost: 6694.262 | Path: [1, 2, 16, 5, 12, 10, 1, 11, 7, 13, 9, 15, 23, 1, 4, 0, 3, 19, 17, 1, 8, 18, 14, 6, 1] Best cost: 6392.828 | Path: [1, 8, 18, 10, 4, 0, 11, 1, 7, 13, 15, 6, 16, 1, 12, 2, 5, 3, 1, 19, 17, 14, 23, 9, 1] Best cost: 6379.763 | Path: [1, 18, 8, 10, 4, 0, 11, 1, 7, 13, 9, 15, 14, 1, 12, 2, 16, 5, 23, 1, 6, 17, 19, 3, 1] OPTIMIZING each tour... Current: [[1, 18, 8, 10, 4, 0, 11, 1], [1, 7, 13, 9, 15, 14, 1], [1, 12, 2, 16, 5, 23, 1], [1, 6, 17, 19, 3, 1]] [1] Cost: 1335.881 to 1327.422 | Optimized: [1, 11, 0, 4, 10, 8, 18, 1] [2] Cost: 1654.419 to 1645.972 | Optimized: [1, 9, 15, 14, 13, 7, 1] [3] Cost: 1958.663 to 1952.632 | Optimized: [1, 12, 2, 5, 16, 23, 1] ACO RESULTS [1/300 vol./1327.422 km] Berlin Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [2/300 vol./1645.972 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/295 vol./1952.632 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Köln Hbf -> Freiburg Hbf --> Berlin Hbf [4/295 vol./1430.800 km] Berlin Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6356.826 km.