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: 17 customers
- Kassel-Wilhelmshöhe (55 vol.)
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (50 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (25 vol.)
- Dresden Hbf (40 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (55 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (100 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (100 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (70 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1783.158 km
LOAD: 295 vol.
- Frankfurt Hbf | 50 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 100 vol.
- Stuttgart Hbf | 25 vol.
- Freiburg Hbf | 35 vol.
Tour 2
COST: 1427.23 km
LOAD: 290 vol.
- Kiel Hbf | 100 vol.
- Bremen Hbf | 55 vol.
- Hannover Hbf | 40 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Dresden Hbf | 40 vol.
Tour 3
COST: 1345.202 km
LOAD: 255 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 100 vol.
Tour 4
COST: 1621.277 km
LOAD: 280 vol.
- Saarbrücken Hbf | 70 vol.
- Aachen Hbf | 80 vol.
- Düsseldorf Hbf | 80 vol.
- Dortmund Hbf | 50 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 50 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 100 vol.
- Stuttgart Hbf | 25 vol.
- Freiburg Hbf | 35 vol.
LOAD: 290 vol.
- Kiel Hbf | 100 vol.
- Bremen Hbf | 55 vol.
- Hannover Hbf | 40 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Dresden Hbf | 40 vol.
LOAD: 255 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 100 vol.
LOAD: 280 vol.
- Saarbrücken Hbf | 70 vol.
- Aachen Hbf | 80 vol.
- Düsseldorf Hbf | 80 vol.
- Dortmund 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: 1120 vol. | Vehicle capacity: 300 vol. Loads: [55, 0, 80, 50, 40, 80, 25, 40, 0, 100, 55, 0, 50, 75, 100, 0, 0, 85, 100, 0, 80, 70, 0, 35] ITERATION Generation: #1 Best cost: 6983.467 | Path: [1, 0, 4, 10, 18, 12, 1, 7, 13, 20, 3, 6, 1, 9, 17, 14, 1, 2, 5, 21, 23, 1] Best cost: 6479.761 | Path: [1, 2, 12, 5, 21, 1, 7, 0, 4, 10, 18, 1, 9, 13, 20, 6, 1, 23, 14, 17, 3, 1] Best cost: 6460.665 | Path: [1, 3, 17, 14, 6, 23, 1, 7, 4, 10, 18, 0, 1, 12, 2, 5, 21, 1, 20, 13, 9, 1] Best cost: 6248.789 | Path: [1, 3, 17, 14, 6, 23, 1, 7, 0, 4, 10, 18, 1, 13, 20, 9, 1, 12, 2, 5, 21, 1] Best cost: 6183.563 | Path: [1, 3, 17, 14, 6, 23, 1, 7, 0, 4, 10, 18, 1, 9, 13, 20, 1, 12, 2, 5, 21, 1] OPTIMIZING each tour... Current: [[1, 3, 17, 14, 6, 23, 1], [1, 7, 0, 4, 10, 18, 1], [1, 9, 13, 20, 1], [1, 12, 2, 5, 21, 1]] [2] Cost: 1428.148 to 1427.230 | Optimized: [1, 18, 10, 4, 0, 7, 1] [3] Cost: 1349.477 to 1345.202 | Optimized: [1, 20, 13, 9, 1] [4] Cost: 1622.780 to 1621.277 | Optimized: [1, 21, 5, 2, 12, 1] ACO RESULTS [1/295 vol./1783.158 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Freiburg Hbf --> Berlin Hbf [2/290 vol./1427.230 km] Berlin Hbf -> Kiel Hbf -> Bremen Hbf -> Hannover Hbf -> Kassel-Wilhelmshöhe -> Dresden Hbf --> Berlin Hbf [3/255 vol./1345.202 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf [4/280 vol./1621.277 km] Berlin Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6176.867 km.