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: 400 vol.
ACTIVE: 21 customers
- Berlin Hbf (95 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (50 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (90 vol.)
- Stuttgart Hbf (65 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (85 vol.)
- Bremen Hbf (80 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (35 vol.)
- Köln Hbf (80 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1348.15 km
LOAD: 395 vol.
- Hannover Hbf | 45 vol.
- Kiel Hbf | 25 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 80 vol.
- Aachen Hbf | 90 vol.
Tour 2
COST: 1267.009 km
LOAD: 380 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 35 vol.
- Berlin Hbf | 95 vol.
- Dresden Hbf | 85 vol.
Tour 3
COST: 1078.186 km
LOAD: 375 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 65 vol.
- Würzburg Hbf | 90 vol.
Tour 4
COST: 1059.805 km
LOAD: 270 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 30 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 50 vol.
LOAD: 395 vol.
- Hannover Hbf | 45 vol.
- Kiel Hbf | 25 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 80 vol.
- Aachen Hbf | 90 vol.
LOAD: 380 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 35 vol.
- Berlin Hbf | 95 vol.
- Dresden Hbf | 85 vol.
LOAD: 375 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 65 vol.
- Würzburg Hbf | 90 vol.
LOAD: 270 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 75 vol.
- Saarbrücken Hbf | 30 vol.
- Mainz Hbf | 35 vol.
- Frankfurt 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1420 vol. | Vehicle capacity: 400 vol. Loads: [0, 95, 95, 50, 45, 90, 65, 85, 35, 85, 80, 0, 60, 100, 80, 35, 80, 0, 25, 35, 90, 30, 85, 75] ITERATION Generation: #1 Best cost: 6032.925 | Path: [0, 1, 7, 13, 20, 21, 0, 22, 10, 4, 8, 18, 2, 19, 0, 12, 16, 5, 3, 14, 15, 0, 6, 23, 9, 0] Best cost: 5321.186 | Path: [0, 2, 16, 5, 12, 4, 18, 0, 3, 19, 14, 6, 15, 9, 21, 0, 22, 10, 8, 1, 7, 0, 20, 13, 23, 0] Best cost: 5313.947 | Path: [0, 3, 19, 14, 6, 15, 9, 21, 0, 12, 2, 16, 5, 4, 18, 0, 22, 10, 8, 1, 7, 0, 20, 13, 23, 0] Best cost: 5210.399 | Path: [0, 10, 22, 12, 2, 16, 0, 4, 8, 18, 1, 7, 13, 0, 19, 3, 20, 6, 14, 23, 0, 5, 21, 15, 9, 0] Best cost: 5046.069 | Path: [0, 6, 14, 23, 21, 19, 3, 12, 0, 2, 16, 5, 22, 4, 0, 20, 13, 9, 15, 7, 0, 10, 8, 18, 1, 0] Best cost: 4852.417 | Path: [0, 2, 16, 5, 12, 4, 18, 0, 20, 13, 9, 15, 6, 0, 22, 10, 8, 1, 7, 0, 19, 3, 14, 23, 21, 0] Generation: #2 Best cost: 4850.669 | Path: [0, 5, 16, 2, 12, 4, 18, 0, 22, 10, 8, 1, 7, 0, 20, 13, 9, 15, 6, 0, 3, 19, 21, 14, 23, 0] Generation: #3 Best cost: 4833.150 | Path: [0, 2, 16, 5, 12, 4, 18, 0, 22, 10, 8, 1, 7, 0, 20, 13, 9, 15, 6, 0, 3, 19, 14, 23, 21, 0] Best cost: 4825.298 | Path: [0, 5, 16, 2, 12, 4, 18, 0, 22, 10, 8, 1, 7, 0, 20, 13, 9, 15, 6, 0, 3, 19, 14, 23, 21, 0] OPTIMIZING each tour... Current: [[0, 5, 16, 2, 12, 4, 18, 0], [0, 22, 10, 8, 1, 7, 0], [0, 20, 13, 9, 15, 6, 0], [0, 3, 19, 14, 23, 21, 0]] [1] Cost: 1372.141 to 1348.150 | Optimized: [0, 4, 18, 12, 2, 16, 5, 0] [3] Cost: 1085.327 to 1078.186 | Optimized: [0, 13, 9, 15, 6, 20, 0] [4] Cost: 1100.821 to 1059.805 | Optimized: [0, 14, 23, 21, 19, 3, 0] ACO RESULTS [1/395 vol./1348.150 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Kiel Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf --> Kassel-Wilhelmshöhe [2/380 vol./1267.009 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Berlin Hbf -> Dresden Hbf --> Kassel-Wilhelmshöhe [3/375 vol./1078.186 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [4/270 vol./1059.805 km] Kassel-Wilhelmshöhe -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4753.150 km.