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 (90 vol.)
- Frankfurt Hbf (35 vol.)
- Aachen Hbf (55 vol.)
- Stuttgart Hbf (80 vol.)
- Dresden Hbf (80 vol.)
- Hamburg Hbf (95 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (95 vol.)
- Dortmund Hbf (75 vol.)
- Nürnberg Hbf (50 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (75 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (60 vol.)
- Mainz Hbf (50 vol.)
- Würzburg Hbf (65 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (80 vol.)
- Freiburg Hbf (40 vol.)
Tour 1
COST: 1756.266 km
LOAD: 275 vol.
- Frankfurt Hbf | 35 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 40 vol.
- Saarbrücken Hbf | 30 vol.
- Mainz Hbf | 50 vol.
Tour 2
COST: 975.554 km
LOAD: 265 vol.
- Dresden Hbf | 80 vol.
- Leipzig Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 90 vol.
Tour 3
COST: 941.643 km
LOAD: 265 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 95 vol.
Tour 4
COST: 1353.16 km
LOAD: 270 vol.
- Würzburg Hbf | 65 vol.
- Stuttgart Hbf | 80 vol.
- Ulm Hbf | 75 vol.
- Nürnberg Hbf | 50 vol.
Tour 5
COST: 1587.331 km
LOAD: 255 vol.
- Dortmund Hbf | 75 vol.
- Köln Hbf | 65 vol.
- Aachen Hbf | 55 vol.
- Kiel Hbf | 60 vol.
LOAD: 275 vol.
- Frankfurt Hbf | 35 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 45 vol.
- Freiburg Hbf | 40 vol.
- Saarbrücken Hbf | 30 vol.
- Mainz Hbf | 50 vol.
LOAD: 265 vol.
- Dresden Hbf | 80 vol.
- Leipzig Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 90 vol.
LOAD: 265 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 95 vol.
LOAD: 270 vol.
- Würzburg Hbf | 65 vol.
- Stuttgart Hbf | 80 vol.
- Ulm Hbf | 75 vol.
- Nürnberg Hbf | 50 vol.
LOAD: 255 vol.
- Dortmund Hbf | 75 vol.
- Köln Hbf | 65 vol.
- Aachen Hbf | 55 vol.
- Kiel 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: 1330 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 0, 35, 0, 55, 80, 80, 95, 0, 90, 95, 75, 50, 45, 75, 65, 75, 60, 50, 65, 30, 80, 40] ITERATION Generation: #1 Best cost: 7974.387 | Path: [1, 0, 22, 10, 3, 1, 7, 11, 13, 20, 1, 8, 18, 12, 16, 1, 19, 17, 14, 6, 23, 1, 15, 21, 5, 1] Best cost: 7868.693 | Path: [1, 3, 19, 17, 14, 6, 1, 7, 11, 0, 21, 1, 8, 18, 10, 5, 1, 22, 12, 16, 20, 1, 13, 15, 23, 1] Best cost: 7511.381 | Path: [1, 5, 16, 12, 22, 1, 11, 7, 13, 20, 1, 8, 18, 10, 3, 1, 0, 19, 17, 14, 23, 1, 15, 6, 21, 1] Best cost: 7502.464 | Path: [1, 7, 11, 13, 20, 1, 8, 18, 10, 5, 1, 22, 12, 16, 19, 21, 1, 0, 3, 17, 14, 23, 1, 6, 15, 1] Best cost: 7409.471 | Path: [1, 17, 14, 6, 15, 1, 11, 7, 13, 20, 1, 22, 12, 16, 5, 1, 8, 18, 10, 3, 1, 0, 19, 21, 23, 1] Best cost: 7195.998 | Path: [1, 21, 19, 3, 17, 14, 23, 1, 7, 11, 0, 1, 8, 18, 10, 5, 1, 13, 20, 6, 15, 1, 22, 12, 16, 1] Best cost: 7181.004 | Path: [1, 19, 3, 17, 14, 6, 1, 7, 11, 20, 13, 1, 12, 16, 5, 21, 23, 1, 8, 18, 10, 1, 22, 0, 15, 1] Best cost: 6917.759 | Path: [1, 21, 19, 3, 17, 14, 23, 1, 7, 11, 0, 1, 8, 10, 22, 1, 13, 20, 6, 15, 1, 18, 12, 16, 5, 1] OPTIMIZING each tour... Current: [[1, 21, 19, 3, 17, 14, 23, 1], [1, 7, 11, 0, 1], [1, 8, 10, 22, 1], [1, 13, 20, 6, 15, 1], [1, 18, 12, 16, 5, 1]] [1] Cost: 1995.152 to 1756.266 | Optimized: [1, 3, 17, 14, 23, 21, 19, 1] [3] Cost: 947.067 to 941.643 | Optimized: [1, 22, 10, 8, 1] [4] Cost: 1410.092 to 1353.160 | Optimized: [1, 20, 6, 15, 13, 1] [5] Cost: 1589.894 to 1587.331 | Optimized: [1, 12, 16, 5, 18, 1] ACO RESULTS [1/275 vol./1756.266 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf --> Berlin Hbf [2/265 vol./ 975.554 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [3/265 vol./ 941.643 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [4/270 vol./1353.160 km] Berlin Hbf -> Würzburg Hbf -> Stuttgart Hbf -> Ulm Hbf -> Nürnberg Hbf --> Berlin Hbf [5/255 vol./1587.331 km] Berlin Hbf -> Dortmund Hbf -> Köln Hbf -> Aachen Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6613.954 km.