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: 15 customers
- Kassel-Wilhelmshöhe (35 vol.)
- Düsseldorf Hbf (50 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (70 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (100 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (50 vol.)
- Karlsruhe Hbf (50 vol.)
- Ulm Hbf (100 vol.)
- Köln Hbf (50 vol.)
- Mainz Hbf (40 vol.)
- Würzburg Hbf (55 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1765.513 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Frankfurt Hbf | 70 vol.
- Karlsruhe Hbf | 50 vol.
- Freiburg Hbf | 45 vol.
- Ulm Hbf | 100 vol.
Tour 2
COST: 1524.292 km
LOAD: 290 vol.
- Köln Hbf | 50 vol.
- Mainz Hbf | 40 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 50 vol.
- Dresden Hbf | 95 vol.
Tour 3
COST: 1160.908 km
LOAD: 255 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 50 vol.
- Osnabrück Hbf | 50 vol.
- Hannover Hbf | 70 vol.
Tour 4
COST: 566.367 km
LOAD: 100 vol.
- Hamburg Hbf | 100 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Frankfurt Hbf | 70 vol.
- Karlsruhe Hbf | 50 vol.
- Freiburg Hbf | 45 vol.
- Ulm Hbf | 100 vol.
LOAD: 290 vol.
- Köln Hbf | 50 vol.
- Mainz Hbf | 40 vol.
- Würzburg Hbf | 55 vol.
- Nürnberg Hbf | 50 vol.
- Dresden Hbf | 95 vol.
LOAD: 255 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 50 vol.
- Osnabrück Hbf | 50 vol.
- Hannover Hbf | 70 vol.
LOAD: 100 vol.
- Hamburg Hbf | 100 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: 945 vol. | Vehicle capacity: 300 vol. Loads: [35, 0, 50, 70, 70, 0, 0, 95, 100, 0, 0, 0, 85, 50, 50, 100, 50, 0, 0, 40, 55, 0, 50, 45] ITERATION Generation: #1 Best cost: 6466.663 | Path: [1, 0, 22, 4, 8, 19, 1, 7, 13, 20, 3, 1, 2, 16, 12, 14, 23, 1, 15, 1] Best cost: 6321.224 | Path: [1, 2, 16, 12, 22, 0, 1, 7, 13, 20, 3, 1, 4, 8, 15, 1, 14, 19, 23, 1] Best cost: 5843.216 | Path: [1, 3, 19, 14, 23, 20, 0, 1, 7, 4, 22, 12, 1, 8, 16, 2, 15, 1, 13, 1] Best cost: 5830.893 | Path: [1, 8, 4, 0, 12, 1, 7, 13, 20, 15, 1, 22, 16, 2, 3, 19, 1, 14, 23, 1] Best cost: 5822.323 | Path: [1, 22, 12, 2, 16, 19, 1, 7, 13, 20, 3, 1, 8, 4, 0, 14, 23, 1, 15, 1] Best cost: 5604.603 | Path: [1, 0, 22, 12, 2, 16, 1, 7, 4, 8, 1, 13, 20, 3, 19, 14, 1, 15, 23, 1] Best cost: 5391.537 | Path: [1, 20, 3, 19, 16, 2, 0, 1, 7, 4, 8, 1, 13, 15, 14, 23, 22, 1, 12, 1] Best cost: 5299.877 | Path: [1, 2, 16, 12, 22, 0, 1, 3, 19, 14, 23, 20, 1, 7, 4, 8, 1, 13, 15, 1] Best cost: 5278.103 | Path: [1, 12, 2, 16, 3, 19, 1, 7, 13, 20, 15, 1, 4, 22, 0, 14, 23, 1, 8, 1] Best cost: 5203.802 | Path: [1, 20, 13, 15, 14, 23, 1, 7, 0, 12, 2, 1, 4, 22, 16, 19, 3, 1, 8, 1] Best cost: 5149.320 | Path: [1, 23, 14, 15, 13, 20, 1, 7, 3, 19, 16, 0, 1, 4, 22, 12, 2, 1, 8, 1] Best cost: 5125.479 | Path: [1, 23, 14, 3, 19, 16, 0, 1, 7, 13, 20, 15, 1, 4, 22, 12, 2, 1, 8, 1] Generation: #2 Best cost: 5117.684 | Path: [1, 3, 19, 14, 23, 16, 0, 1, 7, 13, 20, 15, 1, 4, 22, 12, 2, 1, 8, 1] Best cost: 5046.309 | Path: [1, 15, 14, 23, 3, 0, 1, 7, 13, 20, 19, 16, 1, 4, 22, 12, 2, 1, 8, 1] Generation: #5 Best cost: 5043.457 | Path: [1, 15, 23, 14, 3, 0, 1, 7, 13, 20, 19, 16, 1, 4, 22, 12, 2, 1, 8, 1] OPTIMIZING each tour... Current: [[1, 15, 23, 14, 3, 0, 1], [1, 7, 13, 20, 19, 16, 1], [1, 4, 22, 12, 2, 1], [1, 8, 1]] [1] Cost: 1772.525 to 1765.513 | Optimized: [1, 0, 3, 14, 23, 15, 1] [2] Cost: 1528.268 to 1524.292 | Optimized: [1, 16, 19, 20, 13, 7, 1] [3] Cost: 1176.297 to 1160.908 | Optimized: [1, 12, 2, 22, 4, 1] ACO RESULTS [1/300 vol./1765.513 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Ulm Hbf --> Berlin Hbf [2/290 vol./1524.292 km] Berlin Hbf -> Köln Hbf -> Mainz Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/255 vol./1160.908 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [4/100 vol./ 566.367 km] Berlin Hbf -> Hamburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5017.080 km.