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: 18 customers
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (80 vol.)
- Hannover Hbf (70 vol.)
- Stuttgart Hbf (75 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (100 vol.)
- Bremen Hbf (60 vol.)
- Dortmund Hbf (75 vol.)
- Nürnberg Hbf (90 vol.)
- Karlsruhe Hbf (30 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (95 vol.)
- Kiel Hbf (75 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (60 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1674.119 km
LOAD: 300 vol.
- Mainz Hbf | 75 vol.
- Mannheim Hbf | 95 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 20 vol.
- Frankfurt Hbf | 80 vol.
Tour 2
COST: 1347.336 km
LOAD: 275 vol.
- Würzburg Hbf | 40 vol.
- Stuttgart Hbf | 75 vol.
- Nürnberg Hbf | 90 vol.
- Dresden Hbf | 70 vol.
Tour 3
COST: 1127.197 km
LOAD: 265 vol.
- Hannover Hbf | 70 vol.
- Dortmund Hbf | 75 vol.
- Osnabrück Hbf | 60 vol.
- Bremen Hbf | 60 vol.
Tour 4
COST: 1570.349 km
LOAD: 240 vol.
- Saarbrücken Hbf | 50 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 95 vol.
Tour 5
COST: 732.557 km
LOAD: 175 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 75 vol.
LOAD: 300 vol.
- Mainz Hbf | 75 vol.
- Mannheim Hbf | 95 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 20 vol.
- Frankfurt Hbf | 80 vol.
LOAD: 275 vol.
- Würzburg Hbf | 40 vol.
- Stuttgart Hbf | 75 vol.
- Nürnberg Hbf | 90 vol.
- Dresden Hbf | 70 vol.
LOAD: 265 vol.
- Hannover Hbf | 70 vol.
- Dortmund Hbf | 75 vol.
- Osnabrück Hbf | 60 vol.
- Bremen Hbf | 60 vol.
LOAD: 240 vol.
- Saarbrücken Hbf | 50 vol.
- Köln Hbf | 95 vol.
- Düsseldorf Hbf | 95 vol.
LOAD: 175 vol.
- Hamburg Hbf | 100 vol.
- Kiel 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: 1255 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 95, 80, 70, 0, 75, 70, 100, 0, 60, 0, 75, 90, 30, 0, 95, 95, 75, 75, 40, 50, 60, 20] ITERATION Generation: #1 Best cost: 7155.171 | Path: [1, 2, 16, 12, 14, 1, 7, 13, 20, 3, 23, 1, 4, 10, 8, 22, 1, 19, 17, 6, 21, 1, 18, 1] Best cost: 7025.041 | Path: [1, 17, 19, 3, 20, 1, 7, 13, 6, 14, 23, 1, 4, 22, 10, 8, 1, 18, 12, 2, 21, 1, 16, 1] Best cost: 7000.606 | Path: [1, 21, 14, 17, 19, 20, 1, 7, 13, 6, 23, 1, 8, 18, 10, 22, 1, 4, 12, 16, 1, 2, 3, 1] Best cost: 6956.288 | Path: [1, 23, 14, 17, 3, 19, 1, 7, 13, 20, 6, 1, 8, 18, 10, 22, 1, 4, 12, 2, 21, 1, 16, 1] Best cost: 6942.378 | Path: [1, 19, 3, 17, 14, 23, 1, 7, 13, 20, 6, 1, 8, 18, 10, 22, 1, 4, 12, 2, 21, 1, 16, 1] Best cost: 6863.972 | Path: [1, 3, 19, 17, 14, 23, 1, 7, 4, 10, 8, 1, 13, 20, 6, 21, 1, 18, 22, 12, 1, 16, 2, 1] Best cost: 6809.620 | Path: [1, 23, 14, 17, 3, 19, 1, 7, 4, 10, 8, 1, 12, 2, 16, 1, 18, 22, 21, 6, 20, 1, 13, 1] Generation: #2 Best cost: 6773.135 | Path: [1, 17, 14, 6, 23, 21, 1, 7, 13, 20, 3, 1, 8, 18, 10, 22, 1, 4, 12, 2, 1, 19, 16, 1] Generation: #4 Best cost: 6571.581 | Path: [1, 3, 19, 17, 14, 23, 1, 7, 13, 20, 6, 1, 4, 10, 22, 12, 1, 16, 2, 21, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 17, 14, 23, 1], [1, 7, 13, 20, 6, 1], [1, 4, 10, 22, 12, 1], [1, 16, 2, 21, 1], [1, 8, 18, 1]] [1] Cost: 1674.135 to 1674.119 | Optimized: [1, 19, 17, 14, 23, 3, 1] [2] Cost: 1404.199 to 1347.336 | Optimized: [1, 20, 6, 13, 7, 1] [3] Cost: 1149.331 to 1127.197 | Optimized: [1, 4, 12, 22, 10, 1] [4] Cost: 1611.359 to 1570.349 | Optimized: [1, 21, 16, 2, 1] ACO RESULTS [1/300 vol./1674.119 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Frankfurt Hbf --> Berlin Hbf [2/275 vol./1347.336 km] Berlin Hbf -> Würzburg Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/265 vol./1127.197 km] Berlin Hbf -> Hannover Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf --> Berlin Hbf [4/240 vol./1570.349 km] Berlin Hbf -> Saarbrücken Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf [5/175 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6451.558 km.