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
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (85 vol.)
- Hannover Hbf (65 vol.)
- Stuttgart Hbf (80 vol.)
- Dresden Hbf (50 vol.)
- München Hbf (30 vol.)
- Bremen Hbf (25 vol.)
- Leipzig Hbf (75 vol.)
- Dortmund Hbf (95 vol.)
- Nürnberg Hbf (35 vol.)
- Ulm Hbf (30 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (30 vol.)
- Kiel Hbf (75 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (50 vol.)
- Osnabrück Hbf (45 vol.)
- Freiburg Hbf (30 vol.)
Tour 1
COST: 1373.799 km
LOAD: 280 vol.
- Mainz Hbf | 20 vol.
- Frankfurt Hbf | 85 vol.
- Würzburg Hbf | 50 vol.
- Leipzig Hbf | 75 vol.
- Dresden Hbf | 50 vol.
Tour 2
COST: 1610.07 km
LOAD: 275 vol.
- Mannheim Hbf | 30 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 80 vol.
- Osnabrück Hbf | 45 vol.
- Bremen Hbf | 25 vol.
- Hannover Hbf | 65 vol.
Tour 3
COST: 2020.049 km
LOAD: 300 vol.
- Nürnberg Hbf | 35 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 80 vol.
- Freiburg Hbf | 30 vol.
- Dortmund Hbf | 95 vol.
Tour 4
COST: 701.943 km
LOAD: 75 vol.
- Kiel Hbf | 75 vol.
LOAD: 280 vol.
- Mainz Hbf | 20 vol.
- Frankfurt Hbf | 85 vol.
- Würzburg Hbf | 50 vol.
- Leipzig Hbf | 75 vol.
- Dresden Hbf | 50 vol.
LOAD: 275 vol.
- Mannheim Hbf | 30 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 80 vol.
- Osnabrück Hbf | 45 vol.
- Bremen Hbf | 25 vol.
- Hannover Hbf | 65 vol.
LOAD: 300 vol.
- Nürnberg Hbf | 35 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 80 vol.
- Freiburg Hbf | 30 vol.
- Dortmund Hbf | 95 vol.
LOAD: 75 vol.
- Kiel Hbf | 75 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: 930 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 80, 85, 65, 0, 80, 50, 0, 30, 25, 75, 95, 35, 0, 30, 30, 30, 75, 20, 50, 0, 45, 30] ITERATION Generation: #1 Best cost: 7593.876 | Path: [1, 2, 16, 12, 22, 10, 19, 1, 7, 11, 4, 18, 17, 1, 3, 20, 13, 15, 6, 1, 9, 23, 1] Best cost: 7055.182 | Path: [1, 3, 19, 17, 6, 15, 9, 10, 1, 7, 11, 13, 20, 16, 22, 1, 18, 4, 12, 23, 1, 2, 1] Best cost: 6650.773 | Path: [1, 4, 10, 22, 12, 16, 19, 1, 7, 11, 13, 20, 3, 1, 18, 2, 17, 6, 15, 1, 9, 23, 1] Best cost: 6482.921 | Path: [1, 7, 11, 13, 20, 6, 1, 4, 10, 22, 12, 16, 19, 1, 18, 2, 3, 17, 23, 1, 9, 15, 1] Best cost: 6115.960 | Path: [1, 9, 15, 6, 17, 19, 3, 10, 1, 11, 7, 13, 20, 2, 1, 4, 22, 12, 16, 23, 1, 18, 1] Best cost: 5991.944 | Path: [1, 9, 15, 6, 17, 3, 19, 10, 1, 11, 7, 20, 13, 23, 16, 1, 4, 22, 2, 12, 1, 18, 1] Best cost: 5871.371 | Path: [1, 15, 6, 17, 3, 19, 20, 1, 11, 7, 13, 9, 23, 2, 1, 18, 10, 22, 12, 16, 1, 4, 1] Best cost: 5848.875 | Path: [1, 15, 6, 17, 19, 3, 20, 1, 7, 11, 13, 9, 23, 16, 22, 1, 10, 4, 12, 2, 1, 18, 1] Best cost: 5844.924 | Path: [1, 9, 15, 6, 17, 19, 3, 10, 1, 11, 7, 13, 20, 23, 16, 1, 4, 22, 12, 2, 1, 18, 1] Best cost: 5822.923 | Path: [1, 19, 3, 17, 6, 15, 20, 1, 11, 7, 13, 9, 23, 16, 22, 1, 4, 10, 12, 2, 1, 18, 1] Best cost: 5817.755 | Path: [1, 15, 6, 17, 19, 3, 20, 1, 11, 7, 13, 9, 23, 2, 1, 4, 10, 22, 12, 16, 1, 18, 1] Best cost: 5755.324 | Path: [1, 11, 7, 20, 3, 19, 1, 4, 10, 22, 2, 16, 17, 1, 13, 9, 15, 6, 23, 12, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 20, 3, 19, 1], [1, 4, 10, 22, 2, 16, 17, 1], [1, 13, 9, 15, 6, 23, 12, 1], [1, 18, 1]] [1] Cost: 1412.098 to 1373.799 | Optimized: [1, 19, 3, 20, 11, 7, 1] [2] Cost: 1621.234 to 1610.070 | Optimized: [1, 17, 16, 2, 22, 10, 4, 1] ACO RESULTS [1/280 vol./1373.799 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [2/275 vol./1610.070 km] Berlin Hbf -> Mannheim Hbf -> Köln Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf --> Berlin Hbf [3/300 vol./2020.049 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Dortmund Hbf --> Berlin Hbf [4/ 75 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5705.861 km.