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 (90 vol.)
- Hannover Hbf (20 vol.)
- Stuttgart Hbf (85 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (50 vol.)
- München Hbf (90 vol.)
- Bremen Hbf (85 vol.)
- Leipzig Hbf (90 vol.)
- Dortmund Hbf (35 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (45 vol.)
- Mannheim Hbf (50 vol.)
- Würzburg Hbf (50 vol.)
- Osnabrück Hbf (45 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1082.275 km
LOAD: 270 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 90 vol.
- Hannover Hbf | 20 vol.
- Bremen Hbf | 85 vol.
Tour 2
COST: 1468.224 km
LOAD: 265 vol.
- Frankfurt Hbf | 90 vol.
- Köln Hbf | 45 vol.
- Dortmund Hbf | 35 vol.
- Osnabrück Hbf | 45 vol.
- Hamburg Hbf | 50 vol.
Tour 3
COST: 1447.27 km
LOAD: 270 vol.
- München Hbf | 90 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 85 vol.
Tour 4
COST: 1622.164 km
LOAD: 285 vol.
- Mannheim Hbf | 50 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 85 vol.
- Würzburg Hbf | 50 vol.
LOAD: 270 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 90 vol.
- Hannover Hbf | 20 vol.
- Bremen Hbf | 85 vol.
LOAD: 265 vol.
- Frankfurt Hbf | 90 vol.
- Köln Hbf | 45 vol.
- Dortmund Hbf | 35 vol.
- Osnabrück Hbf | 45 vol.
- Hamburg Hbf | 50 vol.
LOAD: 270 vol.
- München Hbf | 90 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 85 vol.
LOAD: 285 vol.
- Mannheim Hbf | 50 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 85 vol.
- Würzburg Hbf | 50 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: 1090 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 0, 90, 20, 0, 85, 75, 50, 90, 85, 90, 35, 0, 100, 95, 45, 50, 0, 0, 50, 0, 45, 85] ITERATION Generation: #1 Best cost: 6102.240 | Path: [1, 3, 17, 14, 20, 1, 7, 11, 4, 10, 1, 8, 22, 12, 16, 15, 1, 6, 23, 9, 1] Best cost: 5910.209 | Path: [1, 6, 14, 17, 20, 1, 11, 7, 4, 10, 1, 8, 22, 12, 16, 3, 1, 9, 15, 23, 1] Best cost: 5749.766 | Path: [1, 7, 11, 4, 10, 1, 8, 22, 12, 16, 3, 1, 9, 15, 6, 1, 20, 14, 17, 23, 1] Best cost: 5691.475 | Path: [1, 23, 14, 17, 20, 1, 11, 7, 10, 8, 1, 4, 22, 12, 16, 3, 1, 9, 15, 6, 1] Best cost: 5689.914 | Path: [1, 23, 14, 17, 20, 1, 7, 11, 4, 10, 1, 8, 22, 12, 16, 3, 1, 6, 15, 9, 1] Generation: #2 Best cost: 5678.048 | Path: [1, 23, 14, 17, 20, 1, 7, 11, 4, 10, 1, 8, 22, 12, 16, 3, 1, 9, 15, 6, 1] Best cost: 5672.061 | Path: [1, 7, 11, 4, 10, 1, 8, 22, 12, 16, 3, 1, 9, 15, 6, 1, 20, 17, 14, 23, 1] Generation: #3 Best cost: 5631.366 | Path: [1, 7, 11, 4, 10, 1, 8, 22, 12, 16, 3, 1, 9, 15, 6, 1, 17, 14, 23, 20, 1] OPTIMIZING each tour... Current: [[1, 7, 11, 4, 10, 1], [1, 8, 22, 12, 16, 3, 1], [1, 9, 15, 6, 1], [1, 17, 14, 23, 20, 1]] [2] Cost: 1479.657 to 1468.224 | Optimized: [1, 3, 16, 12, 22, 8, 1] ACO RESULTS [1/270 vol./1082.275 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf --> Berlin Hbf [2/265 vol./1468.224 km] Berlin Hbf -> Frankfurt Hbf -> Köln Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Hamburg Hbf --> Berlin Hbf [3/270 vol./1447.270 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf --> Berlin Hbf [4/285 vol./1622.164 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5619.933 km.