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 (95 vol.)
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (20 vol.)
- Aachen Hbf (20 vol.)
- Stuttgart Hbf (25 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (95 vol.)
- München Hbf (20 vol.)
- Bremen Hbf (70 vol.)
- Dortmund Hbf (80 vol.)
- Ulm Hbf (65 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (80 vol.)
- Kiel Hbf (85 vol.)
- Mainz Hbf (45 vol.)
- Würzburg Hbf (45 vol.)
- Osnabrück Hbf (60 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1620.268 km
LOAD: 290 vol.
- München Hbf | 20 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 25 vol.
- Mannheim Hbf | 80 vol.
- Mainz Hbf | 45 vol.
- Frankfurt Hbf | 55 vol.
Tour 2
COST: 2047.602 km
LOAD: 290 vol.
- Dresden Hbf | 75 vol.
- Würzburg Hbf | 45 vol.
- Freiburg Hbf | 35 vol.
- Aachen Hbf | 20 vol.
- Köln Hbf | 55 vol.
- Düsseldorf Hbf | 40 vol.
- Hannover Hbf | 20 vol.
Tour 3
COST: 959.498 km
LOAD: 250 vol.
- Hamburg Hbf | 95 vol.
- Bremen Hbf | 70 vol.
- Kiel Hbf | 85 vol.
Tour 4
COST: 1095.465 km
LOAD: 235 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Dortmund Hbf | 80 vol.
- Osnabrück Hbf | 60 vol.
LOAD: 290 vol.
- München Hbf | 20 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 25 vol.
- Mannheim Hbf | 80 vol.
- Mainz Hbf | 45 vol.
- Frankfurt Hbf | 55 vol.
LOAD: 290 vol.
- Dresden Hbf | 75 vol.
- Würzburg Hbf | 45 vol.
- Freiburg Hbf | 35 vol.
- Aachen Hbf | 20 vol.
- Köln Hbf | 55 vol.
- Düsseldorf Hbf | 40 vol.
- Hannover Hbf | 20 vol.
LOAD: 250 vol.
- Hamburg Hbf | 95 vol.
- Bremen Hbf | 70 vol.
- Kiel Hbf | 85 vol.
LOAD: 235 vol.
- Kassel-Wilhelmshöhe | 95 vol.
- Dortmund Hbf | 80 vol.
- Osnabrück Hbf | 60 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: 1065 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 40, 55, 20, 20, 25, 75, 95, 20, 70, 0, 80, 0, 0, 65, 55, 80, 85, 45, 45, 0, 60, 35] ITERATION Generation: #1 Best cost: 7155.723 | Path: [1, 0, 12, 2, 16, 5, 1, 7, 20, 3, 19, 17, 1, 4, 10, 8, 18, 6, 1, 22, 15, 9, 23, 1] Best cost: 6952.661 | Path: [1, 6, 15, 9, 20, 19, 3, 23, 1, 7, 0, 12, 2, 1, 18, 8, 10, 4, 5, 1, 22, 16, 17, 1] Best cost: 6879.785 | Path: [1, 7, 4, 22, 12, 2, 5, 1, 8, 18, 10, 20, 1, 0, 16, 19, 3, 6, 9, 1, 15, 17, 23, 1] Best cost: 6693.624 | Path: [1, 8, 18, 10, 4, 5, 1, 7, 20, 3, 19, 17, 1, 22, 12, 2, 16, 23, 6, 1, 0, 9, 15, 1] Best cost: 6356.480 | Path: [1, 10, 22, 12, 2, 5, 4, 1, 7, 20, 6, 15, 9, 3, 1, 18, 8, 0, 1, 16, 19, 17, 23, 1] Best cost: 6228.783 | Path: [1, 12, 2, 16, 5, 19, 3, 1, 7, 20, 6, 15, 9, 23, 4, 1, 8, 18, 10, 1, 22, 0, 17, 1] Best cost: 5945.355 | Path: [1, 12, 2, 16, 5, 19, 3, 1, 7, 9, 15, 6, 17, 23, 1, 8, 18, 10, 4, 1, 0, 22, 20, 1] Best cost: 5927.221 | Path: [1, 0, 12, 2, 16, 5, 1, 7, 15, 6, 23, 17, 9, 1, 8, 18, 10, 4, 1, 22, 3, 19, 20, 1] Generation: #2 Best cost: 5790.638 | Path: [1, 3, 19, 17, 6, 15, 9, 1, 7, 20, 23, 16, 2, 5, 4, 1, 8, 18, 10, 1, 0, 12, 22, 1] Generation: #5 Best cost: 5770.602 | Path: [1, 9, 15, 6, 17, 19, 3, 1, 7, 20, 23, 16, 2, 5, 4, 1, 8, 18, 10, 1, 0, 12, 22, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 17, 19, 3, 1], [1, 7, 20, 23, 16, 2, 5, 4, 1], [1, 8, 18, 10, 1], [1, 0, 12, 22, 1]] [2] Cost: 2079.804 to 2047.602 | Optimized: [1, 7, 20, 23, 5, 16, 2, 4, 1] [3] Cost: 975.065 to 959.498 | Optimized: [1, 8, 10, 18, 1] ACO RESULTS [1/290 vol./1620.268 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/290 vol./2047.602 km] Berlin Hbf -> Dresden Hbf -> Würzburg Hbf -> Freiburg Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Hannover Hbf --> Berlin Hbf [3/250 vol./ 959.498 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [4/235 vol./1095.465 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Osnabrück Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5722.833 km.