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 (75 vol.)
- Düsseldorf Hbf (60 vol.)
- Frankfurt Hbf (65 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (50 vol.)
- München Hbf (80 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (80 vol.)
- Köln Hbf (80 vol.)
- Kiel Hbf (90 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (90 vol.)
- Osnabrück Hbf (35 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1483.927 km
LOAD: 270 vol.
- Leipzig Hbf | 20 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 80 vol.
- Stuttgart Hbf | 50 vol.
- Würzburg Hbf | 80 vol.
Tour 2
COST: 1303.653 km
LOAD: 295 vol.
- Hannover Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Osnabrück Hbf | 35 vol.
- Kiel Hbf | 90 vol.
Tour 3
COST: 1291.407 km
LOAD: 275 vol.
- Köln Hbf | 80 vol.
- Aachen Hbf | 80 vol.
- Düsseldorf Hbf | 60 vol.
- Dortmund Hbf | 55 vol.
Tour 4
COST: 1747.028 km
LOAD: 295 vol.
- Frankfurt Hbf | 65 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 60 vol.
- Saarbrücken Hbf | 90 vol.
LOAD: 270 vol.
- Leipzig Hbf | 20 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 80 vol.
- Stuttgart Hbf | 50 vol.
- Würzburg Hbf | 80 vol.
LOAD: 295 vol.
- Hannover Hbf | 95 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Osnabrück Hbf | 35 vol.
- Kiel Hbf | 90 vol.
LOAD: 275 vol.
- Köln Hbf | 80 vol.
- Aachen Hbf | 80 vol.
- Düsseldorf Hbf | 60 vol.
- Dortmund Hbf | 55 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 65 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 60 vol.
- Saarbrücken Hbf | 90 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: 1135 vol. | Vehicle capacity: 300 vol. Loads: [75, 0, 60, 65, 95, 80, 50, 0, 0, 80, 0, 20, 55, 40, 80, 0, 80, 0, 90, 0, 80, 90, 35, 60] ITERATION Generation: #1 Best cost: 7287.706 | Path: [1, 0, 22, 4, 12, 13, 1, 11, 20, 3, 14, 6, 1, 18, 2, 16, 23, 1, 9, 21, 5, 1] Best cost: 6461.152 | Path: [1, 2, 16, 5, 12, 11, 1, 4, 22, 0, 20, 1, 18, 3, 14, 6, 1, 13, 9, 23, 21, 1] Best cost: 6328.453 | Path: [1, 6, 14, 23, 21, 11, 1, 18, 4, 22, 12, 1, 0, 3, 20, 13, 1, 2, 16, 5, 9, 1] Best cost: 6229.070 | Path: [1, 16, 2, 5, 12, 11, 1, 18, 4, 22, 0, 1, 6, 14, 21, 3, 1, 13, 20, 23, 9, 1] Best cost: 6162.418 | Path: [1, 2, 16, 5, 12, 11, 1, 18, 4, 22, 0, 1, 13, 20, 3, 14, 1, 9, 6, 23, 21, 1] Best cost: 6078.171 | Path: [1, 20, 13, 9, 6, 11, 1, 18, 4, 22, 0, 1, 2, 16, 5, 12, 1, 3, 21, 14, 23, 1] Generation: #2 Best cost: 6035.903 | Path: [1, 14, 6, 20, 13, 11, 1, 18, 4, 22, 0, 1, 9, 23, 21, 3, 1, 12, 2, 16, 5, 1] Generation: #3 Best cost: 6006.448 | Path: [1, 20, 13, 9, 6, 11, 1, 18, 4, 22, 0, 1, 12, 2, 16, 5, 1, 3, 14, 23, 21, 1] OPTIMIZING each tour... Current: [[1, 20, 13, 9, 6, 11, 1], [1, 18, 4, 22, 0, 1], [1, 12, 2, 16, 5, 1], [1, 3, 14, 23, 21, 1]] [1] Cost: 1640.741 to 1483.927 | Optimized: [1, 11, 13, 9, 6, 20, 1] [2] Cost: 1310.251 to 1303.653 | Optimized: [1, 4, 0, 22, 18, 1] [3] Cost: 1308.428 to 1291.407 | Optimized: [1, 16, 5, 2, 12, 1] ACO RESULTS [1/270 vol./1483.927 km] Berlin Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [2/295 vol./1303.653 km] Berlin Hbf -> Hannover Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Kiel Hbf --> Berlin Hbf [3/275 vol./1291.407 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf [4/295 vol./1747.028 km] Berlin Hbf -> Frankfurt Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5826.015 km.