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 (55 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (90 vol.)
- Aachen Hbf (65 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (30 vol.)
- Leipzig Hbf (25 vol.)
- Dortmund Hbf (80 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (85 vol.)
- Köln Hbf (25 vol.)
- Mannheim Hbf (60 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1431.522 km
LOAD: 300 vol.
- Dortmund Hbf | 80 vol.
- Düsseldorf Hbf | 95 vol.
- Aachen Hbf | 65 vol.
- Köln Hbf | 25 vol.
- Hamburg Hbf | 35 vol.
Tour 2
COST: 1791.533 km
LOAD: 295 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 25 vol.
- Frankfurt Hbf | 40 vol.
- Mannheim Hbf | 60 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 45 vol.
Tour 3
COST: 1592.489 km
LOAD: 260 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Hannover Hbf | 90 vol.
LOAD: 300 vol.
- Dortmund Hbf | 80 vol.
- Düsseldorf Hbf | 95 vol.
- Aachen Hbf | 65 vol.
- Köln Hbf | 25 vol.
- Hamburg Hbf | 35 vol.
LOAD: 295 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 25 vol.
- Frankfurt Hbf | 40 vol.
- Mannheim Hbf | 60 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 45 vol.
LOAD: 260 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Hannover Hbf | 90 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: 855 vol. | Vehicle capacity: 300 vol. Loads: [55, 0, 95, 40, 90, 65, 0, 25, 35, 30, 0, 25, 80, 0, 100, 85, 25, 60, 0, 0, 0, 0, 0, 45] ITERATION Generation: #1 Best cost: 5479.251 | Path: [1, 0, 11, 7, 9, 15, 17, 1, 8, 4, 12, 2, 1, 16, 5, 3, 14, 23, 1] Best cost: 5193.906 | Path: [1, 2, 16, 5, 12, 8, 1, 11, 7, 0, 4, 3, 17, 1, 9, 15, 14, 23, 1] Best cost: 5186.054 | Path: [1, 5, 16, 2, 12, 8, 1, 11, 7, 0, 4, 3, 17, 1, 9, 15, 14, 23, 1] Best cost: 5072.095 | Path: [1, 16, 2, 12, 5, 8, 1, 7, 11, 9, 15, 14, 1, 4, 0, 3, 17, 23, 1] Best cost: 4958.176 | Path: [1, 16, 2, 5, 12, 8, 1, 7, 11, 4, 0, 3, 17, 1, 9, 15, 14, 23, 1] Best cost: 4938.651 | Path: [1, 2, 16, 5, 12, 8, 1, 7, 11, 4, 0, 3, 17, 1, 9, 15, 14, 23, 1] Best cost: 4919.545 | Path: [1, 2, 16, 5, 12, 8, 1, 11, 7, 3, 17, 14, 23, 1, 4, 0, 15, 9, 1] Best cost: 4911.693 | Path: [1, 5, 16, 2, 12, 8, 1, 11, 7, 3, 17, 14, 23, 1, 4, 0, 15, 9, 1] OPTIMIZING each tour... Current: [[1, 5, 16, 2, 12, 8, 1], [1, 11, 7, 3, 17, 14, 23, 1], [1, 4, 0, 15, 9, 1]] [1] Cost: 1453.777 to 1431.522 | Optimized: [1, 12, 2, 5, 16, 8, 1] [2] Cost: 1856.909 to 1791.533 | Optimized: [1, 7, 11, 3, 17, 14, 23, 1] [3] Cost: 1601.007 to 1592.489 | Optimized: [1, 9, 15, 0, 4, 1] ACO RESULTS [1/300 vol./1431.522 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Köln Hbf -> Hamburg Hbf --> Berlin Hbf [2/295 vol./1791.533 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [3/260 vol./1592.489 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4815.544 km.