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: 20 customers
- Berlin Hbf (45 vol.)
- Düsseldorf Hbf (20 vol.)
- Frankfurt Hbf (65 vol.)
- Hannover Hbf (60 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (75 vol.)
- Dresden Hbf (55 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (90 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (90 vol.)
- Mannheim Hbf (30 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (65 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (20 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 1215.101 km
LOAD: 365 vol.
- Dortmund Hbf | 90 vol.
- Düsseldorf Hbf | 20 vol.
- Aachen Hbf | 60 vol.
- Saarbrücken Hbf | 20 vol.
- Mannheim Hbf | 30 vol.
- Karlsruhe Hbf | 45 vol.
- Stuttgart Hbf | 75 vol.
- Würzburg Hbf | 25 vol.
Tour 2
COST: 1263.139 km
LOAD: 355 vol.
- Hannover Hbf | 60 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 70 vol.
- Berlin Hbf | 45 vol.
Tour 3
COST: 1744.163 km
LOAD: 375 vol.
- Dresden Hbf | 55 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 90 vol.
- Freiburg Hbf | 55 vol.
Tour 4
COST: 465.535 km
LOAD: 130 vol.
- Mainz Hbf | 65 vol.
- Frankfurt Hbf | 65 vol.
LOAD: 365 vol.
- Dortmund Hbf | 90 vol.
- Düsseldorf Hbf | 20 vol.
- Aachen Hbf | 60 vol.
- Saarbrücken Hbf | 20 vol.
- Mannheim Hbf | 30 vol.
- Karlsruhe Hbf | 45 vol.
- Stuttgart Hbf | 75 vol.
- Würzburg Hbf | 25 vol.
LOAD: 355 vol.
- Hannover Hbf | 60 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 90 vol.
- Kiel Hbf | 70 vol.
- Berlin Hbf | 45 vol.
LOAD: 375 vol.
- Dresden Hbf | 55 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 90 vol.
- Freiburg Hbf | 55 vol.
LOAD: 130 vol.
- Mainz Hbf | 65 vol.
- Frankfurt Hbf | 65 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: 1225 vol. | Vehicle capacity: 400 vol. Loads: [0, 45, 20, 65, 60, 60, 75, 55, 90, 95, 90, 0, 90, 80, 45, 90, 0, 30, 70, 65, 25, 20, 0, 55] ITERATION Generation: #1 Best cost: 5332.419 | Path: [0, 1, 7, 13, 20, 3, 19, 17, 21, 0, 12, 2, 5, 4, 10, 18, 0, 6, 14, 23, 15, 9, 0, 8, 0] Best cost: 5117.968 | Path: [0, 3, 19, 17, 14, 6, 15, 20, 0, 2, 5, 12, 4, 10, 18, 0, 1, 7, 13, 9, 23, 21, 0, 8, 0] Best cost: 5110.338 | Path: [0, 5, 2, 12, 4, 10, 18, 0, 3, 19, 17, 14, 6, 15, 20, 0, 1, 7, 13, 9, 23, 21, 0, 8, 0] Best cost: 5092.061 | Path: [0, 18, 8, 10, 4, 12, 0, 19, 3, 17, 14, 6, 15, 20, 0, 2, 5, 21, 23, 13, 9, 7, 0, 1, 0] Best cost: 5039.591 | Path: [0, 3, 19, 17, 14, 6, 15, 20, 0, 4, 10, 8, 18, 12, 0, 2, 5, 21, 23, 13, 9, 7, 0, 1, 0] Best cost: 5030.699 | Path: [0, 18, 8, 10, 4, 12, 0, 20, 13, 9, 15, 6, 17, 0, 3, 19, 14, 23, 21, 5, 2, 1, 0, 7, 0] Best cost: 4951.797 | Path: [0, 20, 13, 9, 15, 6, 17, 0, 3, 19, 14, 23, 21, 2, 12, 0, 4, 10, 8, 18, 1, 0, 5, 7, 0] Best cost: 4941.505 | Path: [0, 8, 18, 10, 4, 12, 0, 3, 19, 17, 14, 6, 15, 20, 0, 2, 5, 21, 23, 9, 13, 7, 0, 1, 0] Best cost: 4910.774 | Path: [0, 3, 19, 17, 14, 6, 15, 20, 0, 12, 2, 5, 21, 23, 9, 7, 0, 4, 10, 8, 18, 1, 0, 13, 0] Best cost: 4865.812 | Path: [0, 7, 1, 8, 18, 4, 2, 5, 0, 20, 13, 9, 15, 6, 17, 0, 12, 19, 3, 14, 23, 21, 0, 10, 0] Generation: #2 Best cost: 4832.360 | Path: [0, 12, 2, 5, 21, 14, 17, 3, 19, 0, 4, 10, 8, 18, 1, 20, 0, 13, 9, 15, 6, 23, 0, 7, 0] Generation: #3 Best cost: 4802.163 | Path: [0, 12, 2, 5, 21, 14, 17, 19, 3, 0, 4, 10, 8, 18, 1, 20, 0, 13, 9, 15, 6, 23, 0, 7, 0] Generation: #4 Best cost: 4782.055 | Path: [0, 9, 15, 6, 14, 17, 3, 0, 12, 2, 5, 19, 21, 23, 13, 0, 20, 7, 1, 8, 18, 10, 0, 4, 0] Generation: #6 Best cost: 4711.180 | Path: [0, 12, 2, 5, 21, 23, 14, 17, 3, 0, 20, 13, 9, 15, 6, 0, 4, 10, 8, 18, 1, 0, 19, 7, 0] Generation: #8 Best cost: 4689.052 | Path: [0, 12, 2, 5, 21, 17, 14, 6, 20, 0, 4, 10, 8, 18, 1, 0, 7, 13, 9, 15, 23, 0, 3, 19, 0] OPTIMIZING each tour... Current: [[0, 12, 2, 5, 21, 17, 14, 6, 20, 0], [0, 4, 10, 8, 18, 1, 0], [0, 7, 13, 9, 15, 23, 0], [0, 3, 19, 0]] [4] Cost: 466.649 to 465.535 | Optimized: [0, 19, 3, 0] ACO RESULTS [1/365 vol./1215.101 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [2/355 vol./1263.139 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe [3/375 vol./1744.163 km] Kassel-Wilhelmshöhe -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [4/130 vol./ 465.535 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4687.938 km.