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: 21 customers
- Kassel-Wilhelmshöhe (100 vol.)
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (35 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (25 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (25 vol.)
- Leipzig Hbf (90 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (90 vol.)
- Karlsruhe Hbf (85 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (60 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (40 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (55 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1842.468 km
LOAD: 300 vol.
- Frankfurt Hbf | 35 vol.
- Mainz Hbf | 55 vol.
- Saarbrücken Hbf | 30 vol.
- Freiburg Hbf | 25 vol.
- Stuttgart Hbf | 25 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 90 vol.
Tour 2
COST: 1007.951 km
LOAD: 300 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 90 vol.
- Hannover Hbf | 25 vol.
- Hamburg Hbf | 100 vol.
Tour 3
COST: 1606.399 km
LOAD: 300 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 50 vol.
- Osnabrück Hbf | 55 vol.
- Kiel Hbf | 60 vol.
Tour 4
COST: 1603.037 km
LOAD: 300 vol.
- München Hbf | 25 vol.
- Karlsruhe Hbf | 85 vol.
- Mannheim Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 100 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 35 vol.
- Mainz Hbf | 55 vol.
- Saarbrücken Hbf | 30 vol.
- Freiburg Hbf | 25 vol.
- Stuttgart Hbf | 25 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 90 vol.
LOAD: 300 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 90 vol.
- Hannover Hbf | 25 vol.
- Hamburg Hbf | 100 vol.
LOAD: 300 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 40 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 50 vol.
- Osnabrück Hbf | 55 vol.
- Kiel Hbf | 60 vol.
LOAD: 300 vol.
- München Hbf | 25 vol.
- Karlsruhe Hbf | 85 vol.
- Mannheim Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 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: 1200 vol. | Vehicle capacity: 300 vol. Loads: [100, 0, 40, 35, 25, 50, 25, 85, 100, 25, 0, 90, 60, 90, 85, 0, 35, 90, 60, 55, 40, 30, 55, 25] ITERATION Generation: #1 Best cost: 7971.243 | Path: [1, 0, 12, 2, 16, 5, 1, 7, 11, 19, 3, 21, 1, 4, 22, 8, 18, 20, 1, 13, 9, 6, 14, 23, 1, 17, 1] Best cost: 7156.575 | Path: [1, 3, 19, 17, 14, 6, 1, 7, 11, 13, 9, 1, 8, 18, 4, 22, 12, 1, 0, 2, 16, 5, 21, 23, 1, 20, 1] Best cost: 6141.842 | Path: [1, 13, 20, 3, 19, 21, 23, 6, 1, 7, 11, 4, 8, 1, 18, 22, 12, 2, 16, 5, 1, 0, 17, 14, 9, 1] OPTIMIZING each tour... Current: [[1, 13, 20, 3, 19, 21, 23, 6, 1], [1, 7, 11, 4, 8, 1], [1, 18, 22, 12, 2, 16, 5, 1], [1, 0, 17, 14, 9, 1]] [1] Cost: 1903.235 to 1842.468 | Optimized: [1, 3, 19, 21, 23, 6, 20, 13, 1] [3] Cost: 1619.618 to 1606.399 | Optimized: [1, 12, 2, 16, 5, 22, 18, 1] [4] Cost: 1611.038 to 1603.037 | Optimized: [1, 9, 14, 17, 0, 1] ACO RESULTS [1/300 vol./1842.468 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Stuttgart Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf [2/300 vol./1007.951 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf [3/300 vol./1606.399 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Osnabrück Hbf -> Kiel Hbf --> Berlin Hbf [4/300 vol./1603.037 km] Berlin Hbf -> München Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6059.855 km.