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: 15 customers
- Frankfurt Hbf (30 vol.)
- Aachen Hbf (90 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (80 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (75 vol.)
- Nürnberg Hbf (90 vol.)
- Karlsruhe Hbf (25 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (95 vol.)
- Mainz Hbf (30 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (20 vol.)
Tour 1
COST: 1218.052 km
LOAD: 285 vol.
- Dresden Hbf | 80 vol.
- Leipzig Hbf | 75 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 40 vol.
Tour 2
COST: 1905.404 km
LOAD: 300 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 60 vol.
- Karlsruhe Hbf | 25 vol.
- Freiburg Hbf | 20 vol.
- Saarbrücken Hbf | 20 vol.
- Würzburg Hbf | 95 vol.
Tour 3
COST: 1475.677 km
LOAD: 245 vol.
- Köln Hbf | 95 vol.
- Aachen Hbf | 90 vol.
- Mainz Hbf | 30 vol.
- Frankfurt Hbf | 30 vol.
Tour 4
COST: 869.684 km
LOAD: 90 vol.
- Nürnberg Hbf | 90 vol.
LOAD: 285 vol.
- Dresden Hbf | 80 vol.
- Leipzig Hbf | 75 vol.
- Osnabrück Hbf | 90 vol.
- Bremen Hbf | 40 vol.
LOAD: 300 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 60 vol.
- Karlsruhe Hbf | 25 vol.
- Freiburg Hbf | 20 vol.
- Saarbrücken Hbf | 20 vol.
- Würzburg Hbf | 95 vol.
LOAD: 245 vol.
- Köln Hbf | 95 vol.
- Aachen Hbf | 90 vol.
- Mainz Hbf | 30 vol.
- Frankfurt Hbf | 30 vol.
LOAD: 90 vol.
- Nürnberg 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: 920 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 0, 30, 0, 90, 60, 80, 0, 0, 40, 75, 0, 90, 25, 80, 95, 0, 0, 30, 95, 20, 90, 20] ITERATION Generation: #1 Best cost: 6365.615 | Path: [1, 3, 19, 20, 13, 14, 23, 1, 11, 7, 10, 22, 1, 16, 5, 21, 6, 1, 15, 1] Best cost: 6292.339 | Path: [1, 10, 22, 16, 19, 3, 1, 7, 11, 13, 14, 23, 1, 20, 6, 15, 21, 1, 5, 1] Best cost: 5923.803 | Path: [1, 15, 6, 14, 19, 3, 21, 23, 1, 11, 7, 20, 10, 1, 22, 16, 5, 1, 13, 1] Best cost: 5889.880 | Path: [1, 3, 19, 21, 14, 6, 15, 23, 1, 11, 7, 20, 10, 1, 22, 16, 5, 1, 13, 1] Best cost: 5704.693 | Path: [1, 21, 14, 23, 6, 15, 13, 1, 11, 7, 20, 3, 1, 19, 16, 5, 10, 1, 22, 1] Generation: #2 Best cost: 5586.440 | Path: [1, 15, 6, 14, 23, 21, 19, 3, 1, 7, 11, 20, 10, 1, 22, 16, 5, 1, 13, 1] Generation: #7 Best cost: 5510.882 | Path: [1, 7, 11, 10, 22, 1, 20, 6, 15, 14, 23, 21, 1, 5, 16, 19, 3, 1, 13, 1] OPTIMIZING each tour... Current: [[1, 7, 11, 10, 22, 1], [1, 20, 6, 15, 14, 23, 21, 1], [1, 5, 16, 19, 3, 1], [1, 13, 1]] [1] Cost: 1221.331 to 1218.052 | Optimized: [1, 7, 11, 22, 10, 1] [2] Cost: 1942.708 to 1905.404 | Optimized: [1, 15, 6, 14, 23, 21, 20, 1] [3] Cost: 1477.159 to 1475.677 | Optimized: [1, 16, 5, 19, 3, 1] ACO RESULTS [1/285 vol./1218.052 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Osnabrück Hbf -> Bremen Hbf --> Berlin Hbf [2/300 vol./1905.404 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Würzburg Hbf --> Berlin Hbf [3/245 vol./1475.677 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [4/ 90 vol./ 869.684 km] Berlin Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5468.817 km.