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: 16 customers
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (75 vol.)
- Aachen Hbf (85 vol.)
- Dresden Hbf (60 vol.)
- Hamburg Hbf (90 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (85 vol.)
- Dortmund Hbf (35 vol.)
- Ulm Hbf (45 vol.)
- Köln Hbf (40 vol.)
- Mannheim Hbf (60 vol.)
- Mainz Hbf (65 vol.)
- Würzburg Hbf (20 vol.)
- Saarbrücken Hbf (95 vol.)
- Osnabrück Hbf (35 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1565.811 km
LOAD: 295 vol.
- Würzburg Hbf | 20 vol.
- Frankfurt Hbf | 80 vol.
- Köln Hbf | 40 vol.
- Aachen Hbf | 85 vol.
- Dortmund Hbf | 35 vol.
- Osnabrück Hbf | 35 vol.
Tour 2
COST: 805.867 km
LOAD: 260 vol.
- Hannover Hbf | 75 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 90 vol.
Tour 3
COST: 1437.279 km
LOAD: 270 vol.
- Dresden Hbf | 60 vol.
- Leipzig Hbf | 85 vol.
- Mainz Hbf | 65 vol.
- Mannheim Hbf | 60 vol.
Tour 4
COST: 1833.82 km
LOAD: 185 vol.
- Ulm Hbf | 45 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 95 vol.
LOAD: 295 vol.
- Würzburg Hbf | 20 vol.
- Frankfurt Hbf | 80 vol.
- Köln Hbf | 40 vol.
- Aachen Hbf | 85 vol.
- Dortmund Hbf | 35 vol.
- Osnabrück Hbf | 35 vol.
LOAD: 260 vol.
- Hannover Hbf | 75 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 90 vol.
LOAD: 270 vol.
- Dresden Hbf | 60 vol.
- Leipzig Hbf | 85 vol.
- Mainz Hbf | 65 vol.
- Mannheim Hbf | 60 vol.
LOAD: 185 vol.
- Ulm Hbf | 45 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 95 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: 1010 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 0, 80, 75, 85, 0, 60, 90, 0, 95, 85, 35, 0, 0, 45, 40, 60, 0, 65, 20, 95, 35, 45] ITERATION Generation: #1 Best cost: 6400.662 | Path: [1, 3, 19, 17, 21, 1, 7, 11, 4, 22, 12, 1, 8, 10, 5, 20, 1, 16, 23, 15, 1] Best cost: 6340.862 | Path: [1, 4, 10, 8, 22, 1, 11, 7, 20, 3, 16, 1, 12, 5, 19, 17, 23, 1, 21, 15, 1] Best cost: 6252.449 | Path: [1, 8, 10, 4, 22, 1, 11, 7, 20, 3, 16, 1, 12, 5, 19, 17, 23, 1, 15, 21, 1] Best cost: 6206.246 | Path: [1, 21, 17, 19, 3, 1, 7, 11, 20, 15, 23, 16, 1, 4, 10, 22, 12, 1, 8, 5, 1] Best cost: 6175.774 | Path: [1, 22, 10, 4, 8, 1, 11, 7, 20, 3, 12, 1, 19, 17, 21, 23, 1, 16, 5, 15, 1] Best cost: 6142.710 | Path: [1, 4, 10, 8, 22, 1, 11, 7, 20, 3, 16, 1, 12, 5, 21, 17, 1, 19, 23, 15, 1] Best cost: 5967.600 | Path: [1, 8, 10, 4, 22, 1, 11, 7, 15, 20, 3, 1, 12, 16, 5, 21, 23, 1, 17, 19, 1] Best cost: 5655.570 | Path: [1, 22, 12, 16, 5, 3, 20, 1, 4, 10, 8, 1, 7, 11, 19, 17, 1, 21, 23, 15, 1] OPTIMIZING each tour... Current: [[1, 22, 12, 16, 5, 3, 20, 1], [1, 4, 10, 8, 1], [1, 7, 11, 19, 17, 1], [1, 21, 23, 15, 1]] [1] Cost: 1578.055 to 1565.811 | Optimized: [1, 20, 3, 16, 5, 12, 22, 1] [4] Cost: 1834.369 to 1833.820 | Optimized: [1, 15, 23, 21, 1] ACO RESULTS [1/295 vol./1565.811 km] Berlin Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Köln Hbf -> Aachen Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Berlin Hbf [2/260 vol./ 805.867 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/270 vol./1437.279 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Mainz Hbf -> Mannheim Hbf --> Berlin Hbf [4/185 vol./1833.820 km] Berlin Hbf -> Ulm Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5642.777 km.