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: 22 customers
- Kassel-Wilhelmshöhe (45 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (85 vol.)
- Hannover Hbf (90 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (30 vol.)
- Bremen Hbf (60 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (50 vol.)
- Köln Hbf (35 vol.)
- Mannheim Hbf (80 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1308.774 km
LOAD: 290 vol.
- Dortmund Hbf | 50 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 35 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 60 vol.
Tour 2
COST: 1632.633 km
LOAD: 265 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Würzburg Hbf | 25 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 30 vol.
- Leipzig Hbf | 35 vol.
- Dresden Hbf | 90 vol.
Tour 3
COST: 881.934 km
LOAD: 255 vol.
- Hannover Hbf | 90 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 80 vol.
Tour 4
COST: 1430.419 km
LOAD: 295 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 80 vol.
- Karlsruhe Hbf | 100 vol.
- Stuttgart Hbf | 60 vol.
Tour 5
COST: 1841.638 km
LOAD: 300 vol.
- Frankfurt Hbf | 85 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 85 vol.
- Ulm Hbf | 50 vol.
LOAD: 290 vol.
- Dortmund Hbf | 50 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 35 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 60 vol.
LOAD: 265 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Würzburg Hbf | 25 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 30 vol.
- Leipzig Hbf | 35 vol.
- Dresden Hbf | 90 vol.
LOAD: 255 vol.
- Hannover Hbf | 90 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 80 vol.
LOAD: 295 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 80 vol.
- Karlsruhe Hbf | 100 vol.
- Stuttgart Hbf | 60 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 85 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 85 vol.
- Ulm Hbf | 50 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: 1405 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 95, 85, 90, 0, 60, 90, 85, 30, 60, 35, 50, 40, 100, 50, 35, 80, 80, 55, 25, 80, 50, 85] ITERATION Generation: #1 Best cost: 7642.716 | Path: [1, 0, 4, 10, 22, 12, 1, 11, 7, 13, 20, 3, 1, 8, 18, 2, 16, 1, 19, 21, 23, 17, 1, 9, 15, 6, 14, 1] Best cost: 7252.615 | Path: [1, 6, 14, 17, 19, 1, 7, 11, 13, 20, 3, 1, 8, 18, 10, 22, 1, 4, 0, 12, 2, 1, 16, 21, 23, 15, 9, 1] Best cost: 7221.639 | Path: [1, 7, 11, 13, 20, 3, 1, 18, 8, 10, 22, 1, 4, 0, 12, 2, 1, 19, 17, 14, 6, 1, 9, 15, 23, 21, 16, 1] Best cost: 7129.691 | Path: [1, 16, 2, 12, 22, 10, 1, 7, 11, 0, 20, 13, 9, 1, 4, 8, 18, 1, 6, 14, 17, 19, 1, 3, 21, 23, 15, 1] OPTIMIZING each tour... Current: [[1, 16, 2, 12, 22, 10, 1], [1, 7, 11, 0, 20, 13, 9, 1], [1, 4, 8, 18, 1], [1, 6, 14, 17, 19, 1], [1, 3, 21, 23, 15, 1]] [1] Cost: 1311.888 to 1308.774 | Optimized: [1, 12, 2, 16, 22, 10, 1] [2] Cost: 1660.555 to 1632.633 | Optimized: [1, 0, 20, 13, 9, 11, 7, 1] [4] Cost: 1433.676 to 1430.419 | Optimized: [1, 19, 17, 14, 6, 1] ACO RESULTS [1/290 vol./1308.774 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Osnabrück Hbf -> Bremen Hbf --> Berlin Hbf [2/265 vol./1632.633 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/255 vol./ 881.934 km] Berlin Hbf -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/295 vol./1430.419 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf --> Berlin Hbf [5/300 vol./1841.638 km] Berlin Hbf -> Frankfurt Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Ulm Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7095.398 km.