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 (50 vol.)
- Düsseldorf Hbf (60 vol.)
- Frankfurt Hbf (50 vol.)
- Hannover Hbf (85 vol.)
- Aachen Hbf (35 vol.)
- Dresden Hbf (40 vol.)
- Hamburg Hbf (95 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (45 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (50 vol.)
- Ulm Hbf (70 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (85 vol.)
- Mainz Hbf (40 vol.)
- Würzburg Hbf (85 vol.)
- Saarbrücken Hbf (60 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1237.262 km
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Dortmund Hbf | 45 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 55 vol.
- Hannover Hbf | 85 vol.
Tour 2
COST: 1438.037 km
LOAD: 295 vol.
- Mainz Hbf | 40 vol.
- Frankfurt Hbf | 50 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 60 vol.
- Leipzig Hbf | 20 vol.
- Dresden Hbf | 40 vol.
Tour 3
COST: 959.498 km
LOAD: 280 vol.
- Hamburg Hbf | 95 vol.
- Bremen Hbf | 100 vol.
- Kiel Hbf | 85 vol.
Tour 4
COST: 1919.566 km
LOAD: 300 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 50 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 60 vol.
- Aachen Hbf | 35 vol.
Tour 5
COST: 1346.514 km
LOAD: 130 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 70 vol.
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Dortmund Hbf | 45 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 55 vol.
- Hannover Hbf | 85 vol.
LOAD: 295 vol.
- Mainz Hbf | 40 vol.
- Frankfurt Hbf | 50 vol.
- Würzburg Hbf | 85 vol.
- Nürnberg Hbf | 60 vol.
- Leipzig Hbf | 20 vol.
- Dresden Hbf | 40 vol.
LOAD: 280 vol.
- Hamburg Hbf | 95 vol.
- Bremen Hbf | 100 vol.
- Kiel Hbf | 85 vol.
LOAD: 300 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 50 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 60 vol.
- Aachen Hbf | 35 vol.
LOAD: 130 vol.
- München Hbf | 60 vol.
- Ulm Hbf | 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: 1300 vol. | Vehicle capacity: 300 vol. Loads: [50, 0, 60, 50, 85, 35, 0, 40, 95, 60, 100, 20, 45, 60, 50, 70, 55, 75, 85, 40, 85, 60, 0, 80] ITERATION Generation: #1 Best cost: 8201.016 | Path: [1, 0, 12, 2, 16, 5, 19, 1, 11, 7, 4, 10, 3, 1, 8, 18, 20, 1, 13, 9, 15, 14, 21, 1, 17, 23, 1] Best cost: 7663.899 | Path: [1, 3, 19, 17, 14, 21, 11, 1, 7, 13, 20, 15, 5, 1, 18, 8, 10, 1, 4, 0, 12, 2, 16, 1, 9, 23, 1] Best cost: 7501.687 | Path: [1, 4, 10, 8, 11, 1, 7, 13, 20, 3, 19, 1, 18, 12, 2, 16, 5, 1, 0, 17, 14, 15, 1, 9, 23, 21, 1] Best cost: 7270.922 | Path: [1, 7, 11, 13, 20, 3, 19, 1, 4, 10, 8, 1, 18, 12, 2, 16, 5, 1, 0, 17, 14, 23, 1, 9, 15, 21, 1] Best cost: 7169.739 | Path: [1, 11, 7, 13, 20, 3, 19, 1, 8, 10, 4, 1, 18, 0, 12, 16, 2, 1, 17, 14, 23, 21, 5, 1, 9, 15, 1] Best cost: 6977.391 | Path: [1, 16, 2, 12, 0, 4, 1, 7, 11, 13, 20, 3, 19, 1, 8, 10, 18, 1, 17, 14, 23, 21, 5, 1, 9, 15, 1] OPTIMIZING each tour... Current: [[1, 16, 2, 12, 0, 4, 1], [1, 7, 11, 13, 20, 3, 19, 1], [1, 8, 10, 18, 1], [1, 17, 14, 23, 21, 5, 1], [1, 9, 15, 1]] [1] Cost: 1307.353 to 1237.262 | Optimized: [1, 0, 12, 2, 16, 4, 1] [2] Cost: 1444.460 to 1438.037 | Optimized: [1, 19, 3, 20, 13, 11, 7, 1] ACO RESULTS [1/295 vol./1237.262 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Hannover Hbf --> Berlin Hbf [2/295 vol./1438.037 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/280 vol./ 959.498 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [4/300 vol./1919.566 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf --> Berlin Hbf [5/130 vol./1346.514 km] Berlin Hbf -> München Hbf -> Ulm Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6900.877 km.