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 (70 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (85 vol.)
- Dresden Hbf (30 vol.)
- Hamburg Hbf (45 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (70 vol.)
- Leipzig Hbf (70 vol.)
- Dortmund Hbf (40 vol.)
- Karlsruhe Hbf (55 vol.)
- Köln Hbf (25 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (40 vol.)
Tour 1
COST: 1606.514 km
LOAD: 300 vol.
- München Hbf | 40 vol.
- Stuttgart Hbf | 85 vol.
- Karlsruhe Hbf | 55 vol.
- Mannheim Hbf | 20 vol.
- Mainz Hbf | 100 vol.
Tour 2
COST: 1307.607 km
LOAD: 285 vol.
- Frankfurt Hbf | 95 vol.
- Würzburg Hbf | 90 vol.
- Leipzig Hbf | 70 vol.
- Dresden Hbf | 30 vol.
Tour 3
COST: 1107.833 km
LOAD: 290 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 90 vol.
Tour 4
COST: 1942.704 km
LOAD: 290 vol.
- Hannover Hbf | 55 vol.
- Dortmund Hbf | 40 vol.
- Köln Hbf | 25 vol.
- Aachen Hbf | 30 vol.
- Saarbrücken Hbf | 100 vol.
- Freiburg Hbf | 40 vol.
Tour 5
COST: 785.078 km
LOAD: 70 vol.
- Kassel-Wilhelmshöhe | 70 vol.
LOAD: 300 vol.
- München Hbf | 40 vol.
- Stuttgart Hbf | 85 vol.
- Karlsruhe Hbf | 55 vol.
- Mannheim Hbf | 20 vol.
- Mainz Hbf | 100 vol.
LOAD: 285 vol.
- Frankfurt Hbf | 95 vol.
- Würzburg Hbf | 90 vol.
- Leipzig Hbf | 70 vol.
- Dresden Hbf | 30 vol.
LOAD: 290 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 90 vol.
LOAD: 290 vol.
- Hannover Hbf | 55 vol.
- Dortmund Hbf | 40 vol.
- Köln Hbf | 25 vol.
- Aachen Hbf | 30 vol.
- Saarbrücken Hbf | 100 vol.
- Freiburg Hbf | 40 vol.
LOAD: 70 vol.
- Kassel-Wilhelmshöhe | 70 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: 1235 vol. | Vehicle capacity: 300 vol. Loads: [70, 0, 0, 95, 55, 30, 85, 30, 45, 40, 70, 70, 40, 0, 55, 0, 25, 20, 90, 100, 90, 100, 85, 40] ITERATION Generation: #1 Best cost: 7976.692 | Path: [1, 0, 12, 22, 4, 8, 1, 7, 11, 20, 3, 1, 10, 18, 16, 5, 14, 17, 1, 19, 21, 23, 9, 1, 6, 1] Best cost: 7730.464 | Path: [1, 4, 10, 8, 18, 7, 1, 11, 0, 22, 12, 16, 1, 20, 3, 19, 1, 9, 6, 14, 17, 21, 1, 5, 23, 1] Best cost: 7128.742 | Path: [1, 8, 18, 10, 4, 12, 1, 7, 11, 9, 6, 14, 17, 1, 3, 19, 20, 1, 22, 16, 5, 21, 23, 1, 0, 1] Best cost: 6811.575 | Path: [1, 9, 6, 14, 17, 19, 1, 11, 7, 20, 3, 1, 8, 18, 10, 22, 1, 4, 12, 16, 5, 21, 23, 1, 0, 1] Generation: #3 Best cost: 6800.746 | Path: [1, 9, 6, 14, 17, 19, 1, 11, 7, 20, 3, 1, 18, 8, 10, 22, 1, 4, 12, 16, 5, 21, 23, 1, 0, 1] OPTIMIZING each tour... Current: [[1, 9, 6, 14, 17, 19, 1], [1, 11, 7, 20, 3, 1], [1, 18, 8, 10, 22, 1], [1, 4, 12, 16, 5, 21, 23, 1], [1, 0, 1]] [2] Cost: 1344.791 to 1307.607 | Optimized: [1, 3, 20, 11, 7, 1] [3] Cost: 1121.659 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] ACO RESULTS [1/300 vol./1606.514 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Mainz Hbf --> Berlin Hbf [2/285 vol./1307.607 km] Berlin Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/290 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/290 vol./1942.704 km] Berlin Hbf -> Hannover Hbf -> Dortmund Hbf -> Köln Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Freiburg Hbf --> Berlin Hbf [5/ 70 vol./ 785.078 km] Berlin Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6749.736 km.