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: 18 customers
- Kassel-Wilhelmshöhe (60 vol.)
- Düsseldorf Hbf (75 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (25 vol.)
- Stuttgart Hbf (80 vol.)
- Hamburg Hbf (45 vol.)
- München Hbf (45 vol.)
- Bremen Hbf (55 vol.)
- Dortmund Hbf (70 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (95 vol.)
- Mannheim Hbf (65 vol.)
- Kiel Hbf (45 vol.)
- Würzburg Hbf (35 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (75 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1256.055 km
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 45 vol.
Tour 2
COST: 1476.746 km
LOAD: 295 vol.
- Frankfurt Hbf | 60 vol.
- Mannheim Hbf | 65 vol.
- Düsseldorf Hbf | 75 vol.
- Dortmund Hbf | 70 vol.
- Hannover Hbf | 25 vol.
Tour 3
COST: 1458.561 km
LOAD: 285 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 80 vol.
- Nürnberg Hbf | 65 vol.
Tour 4
COST: 1735.648 km
LOAD: 255 vol.
- Würzburg Hbf | 35 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 60 vol.
LOAD: 280 vol.
- Kassel-Wilhelmshöhe | 60 vol.
- Osnabrück Hbf | 75 vol.
- Bremen Hbf | 55 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 45 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 60 vol.
- Mannheim Hbf | 65 vol.
- Düsseldorf Hbf | 75 vol.
- Dortmund Hbf | 70 vol.
- Hannover Hbf | 25 vol.
LOAD: 285 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 95 vol.
- Stuttgart Hbf | 80 vol.
- Nürnberg Hbf | 65 vol.
LOAD: 255 vol.
- Würzburg Hbf | 35 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 60 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: 1115 vol. | Vehicle capacity: 300 vol. Loads: [60, 0, 75, 60, 25, 0, 80, 0, 45, 45, 55, 0, 70, 65, 80, 95, 0, 65, 45, 0, 35, 60, 75, 80] ITERATION Generation: #1 Best cost: 6712.428 | Path: [1, 0, 12, 2, 22, 1, 10, 8, 18, 4, 17, 3, 1, 20, 13, 9, 15, 21, 1, 6, 14, 23, 1] Best cost: 6538.917 | Path: [1, 2, 12, 22, 4, 10, 1, 8, 18, 0, 3, 17, 1, 13, 20, 6, 15, 1, 9, 14, 21, 23, 1] Best cost: 6420.459 | Path: [1, 4, 10, 22, 2, 12, 1, 8, 18, 0, 20, 6, 1, 13, 9, 15, 14, 1, 3, 17, 21, 23, 1] Best cost: 6148.584 | Path: [1, 0, 22, 10, 8, 18, 1, 4, 12, 2, 3, 17, 1, 13, 20, 6, 14, 1, 21, 23, 15, 9, 1] Best cost: 5951.261 | Path: [1, 0, 22, 10, 8, 18, 1, 4, 12, 2, 3, 17, 1, 13, 9, 15, 6, 1, 20, 14, 23, 21, 1] OPTIMIZING each tour... Current: [[1, 0, 22, 10, 8, 18, 1], [1, 4, 12, 2, 3, 17, 1], [1, 13, 9, 15, 6, 1], [1, 20, 14, 23, 21, 1]] [2] Cost: 1492.481 to 1476.746 | Optimized: [1, 3, 17, 2, 12, 4, 1] [3] Cost: 1467.077 to 1458.561 | Optimized: [1, 9, 15, 6, 13, 1] ACO RESULTS [1/280 vol./1256.055 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [2/295 vol./1476.746 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Hannover Hbf --> Berlin Hbf [3/285 vol./1458.561 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Nürnberg Hbf --> Berlin Hbf [4/255 vol./1735.648 km] Berlin Hbf -> Würzburg Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5927.010 km.