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: 17 customers
- Kassel-Wilhelmshöhe (40 vol.)
- Düsseldorf Hbf (50 vol.)
- Aachen Hbf (65 vol.)
- Stuttgart Hbf (75 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (40 vol.)
- Nürnberg Hbf (20 vol.)
- Ulm Hbf (70 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (50 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (85 vol.)
- Saarbrücken Hbf (70 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1429.305 km
LOAD: 290 vol.
- Leipzig Hbf | 40 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 95 vol.
- Aachen Hbf | 65 vol.
Tour 2
COST: 1663.643 km
LOAD: 295 vol.
- Dresden Hbf | 75 vol.
- Nürnberg Hbf | 20 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 70 vol.
- Mannheim Hbf | 50 vol.
Tour 3
COST: 959.498 km
LOAD: 240 vol.
- Hamburg Hbf | 100 vol.
- Bremen Hbf | 40 vol.
- Kiel Hbf | 100 vol.
Tour 4
COST: 1763.494 km
LOAD: 300 vol.
- Mainz Hbf | 85 vol.
- Saarbrücken Hbf | 70 vol.
- Freiburg Hbf | 70 vol.
- Stuttgart Hbf | 75 vol.
LOAD: 290 vol.
- Leipzig Hbf | 40 vol.
- Kassel-Wilhelmshöhe | 40 vol.
- Düsseldorf Hbf | 50 vol.
- Köln Hbf | 95 vol.
- Aachen Hbf | 65 vol.
LOAD: 295 vol.
- Dresden Hbf | 75 vol.
- Nürnberg Hbf | 20 vol.
- München Hbf | 80 vol.
- Ulm Hbf | 70 vol.
- Mannheim Hbf | 50 vol.
LOAD: 240 vol.
- Hamburg Hbf | 100 vol.
- Bremen Hbf | 40 vol.
- Kiel Hbf | 100 vol.
LOAD: 300 vol.
- Mainz Hbf | 85 vol.
- Saarbrücken Hbf | 70 vol.
- Freiburg Hbf | 70 vol.
- Stuttgart Hbf | 75 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: 1125 vol. | Vehicle capacity: 300 vol. Loads: [40, 0, 50, 0, 0, 65, 75, 75, 100, 80, 40, 40, 0, 20, 0, 70, 95, 50, 100, 85, 0, 70, 0, 70] ITERATION Generation: #1 Best cost: 7412.483 | Path: [1, 0, 10, 8, 18, 13, 1, 11, 7, 9, 15, 1, 6, 19, 17, 21, 1, 5, 16, 2, 23, 1] Best cost: 6537.076 | Path: [1, 2, 16, 5, 19, 1, 11, 7, 13, 9, 15, 1, 8, 10, 18, 0, 1, 21, 6, 17, 23, 1] Best cost: 6399.906 | Path: [1, 5, 16, 2, 19, 1, 7, 11, 6, 15, 13, 1, 8, 18, 10, 0, 1, 9, 17, 21, 23, 1] Best cost: 6327.914 | Path: [1, 7, 11, 0, 19, 17, 1, 8, 18, 10, 2, 1, 9, 15, 6, 13, 1, 16, 5, 21, 23, 1] Best cost: 6261.731 | Path: [1, 9, 15, 6, 17, 13, 1, 7, 11, 0, 2, 16, 1, 18, 8, 10, 1, 19, 21, 5, 23, 1] Best cost: 6120.894 | Path: [1, 13, 9, 15, 6, 17, 1, 11, 7, 0, 2, 16, 1, 8, 18, 10, 1, 19, 21, 23, 5, 1] Best cost: 6109.625 | Path: [1, 13, 9, 15, 6, 17, 1, 11, 7, 0, 2, 16, 1, 10, 8, 18, 1, 19, 21, 23, 5, 1] Best cost: 6096.506 | Path: [1, 19, 17, 6, 15, 13, 1, 11, 7, 0, 2, 16, 1, 8, 18, 10, 1, 9, 23, 21, 5, 1] Best cost: 6043.885 | Path: [1, 9, 15, 6, 17, 13, 1, 7, 11, 0, 2, 16, 1, 8, 18, 10, 1, 5, 19, 21, 23, 1] Best cost: 5926.765 | Path: [1, 0, 16, 2, 5, 17, 1, 7, 11, 13, 9, 15, 1, 8, 18, 10, 1, 6, 23, 21, 19, 1] Best cost: 5906.757 | Path: [1, 0, 2, 16, 5, 17, 1, 7, 11, 13, 9, 15, 1, 8, 18, 10, 1, 19, 21, 23, 6, 1] Best cost: 5832.022 | Path: [1, 5, 16, 2, 0, 11, 1, 7, 13, 9, 15, 17, 1, 8, 18, 10, 1, 19, 21, 23, 6, 1] OPTIMIZING each tour... Current: [[1, 5, 16, 2, 0, 11, 1], [1, 7, 13, 9, 15, 17, 1], [1, 8, 18, 10, 1], [1, 19, 21, 23, 6, 1]] [1] Cost: 1429.820 to 1429.305 | Optimized: [1, 11, 0, 2, 16, 5, 1] [3] Cost: 975.065 to 959.498 | Optimized: [1, 8, 10, 18, 1] ACO RESULTS [1/290 vol./1429.305 km] Berlin Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf [2/295 vol./1663.643 km] Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Mannheim Hbf --> Berlin Hbf [3/240 vol./ 959.498 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [4/300 vol./1763.494 km] Berlin Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Stuttgart Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5815.940 km.