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
- Düsseldorf Hbf (30 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (40 vol.)
- Stuttgart Hbf (45 vol.)
- Hamburg Hbf (60 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (60 vol.)
- Dortmund Hbf (70 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (100 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (30 vol.)
- Mainz Hbf (40 vol.)
- Saarbrücken Hbf (85 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1520.496 km
LOAD: 290 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 30 vol.
- Köln Hbf | 65 vol.
- Mainz Hbf | 40 vol.
- Frankfurt Hbf | 55 vol.
- Mannheim Hbf | 30 vol.
Tour 2
COST: 1387.509 km
LOAD: 285 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 45 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 60 vol.
Tour 3
COST: 947.647 km
LOAD: 260 vol.
- Hannover Hbf | 40 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 60 vol.
Tour 4
COST: 1738.161 km
LOAD: 225 vol.
- Saarbrücken Hbf | 85 vol.
- Freiburg Hbf | 85 vol.
- Karlsruhe Hbf | 55 vol.
LOAD: 290 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 30 vol.
- Köln Hbf | 65 vol.
- Mainz Hbf | 40 vol.
- Frankfurt Hbf | 55 vol.
- Mannheim Hbf | 30 vol.
LOAD: 285 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 45 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 60 vol.
LOAD: 260 vol.
- Hannover Hbf | 40 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 90 vol.
- Hamburg Hbf | 60 vol.
LOAD: 225 vol.
- Saarbrücken Hbf | 85 vol.
- Freiburg Hbf | 85 vol.
- Karlsruhe Hbf | 55 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: 1060 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 30, 55, 40, 0, 45, 0, 60, 0, 90, 60, 70, 80, 55, 100, 65, 30, 0, 40, 0, 85, 70, 85] ITERATION Generation: #1 Best cost: 6024.835 | Path: [1, 2, 16, 12, 22, 4, 1, 11, 13, 15, 6, 1, 8, 10, 3, 19, 17, 1, 21, 14, 23, 1] Best cost: 6017.159 | Path: [1, 8, 10, 22, 12, 1, 11, 4, 2, 16, 19, 3, 1, 13, 15, 6, 14, 1, 21, 17, 23, 1] Best cost: 5866.469 | Path: [1, 11, 13, 15, 6, 1, 8, 10, 4, 22, 2, 1, 17, 14, 23, 21, 19, 1, 12, 16, 3, 1] Best cost: 5731.340 | Path: [1, 6, 15, 14, 17, 3, 1, 11, 19, 16, 2, 12, 1, 4, 22, 10, 8, 1, 13, 21, 23, 1] Best cost: 5672.232 | Path: [1, 12, 2, 16, 19, 3, 17, 1, 11, 13, 15, 6, 1, 8, 10, 22, 4, 1, 23, 14, 21, 1] Generation: #2 Best cost: 5602.097 | Path: [1, 12, 2, 16, 19, 3, 17, 1, 11, 13, 15, 6, 1, 8, 10, 22, 4, 1, 14, 23, 21, 1] Generation: #3 Best cost: 5598.218 | Path: [1, 12, 2, 16, 19, 3, 17, 1, 11, 13, 15, 6, 1, 4, 22, 10, 8, 1, 14, 23, 21, 1] OPTIMIZING each tour... Current: [[1, 12, 2, 16, 19, 3, 17, 1], [1, 11, 13, 15, 6, 1], [1, 4, 22, 10, 8, 1], [1, 14, 23, 21, 1]] [2] Cost: 1389.964 to 1387.509 | Optimized: [1, 15, 6, 13, 11, 1] [4] Cost: 1740.111 to 1738.161 | Optimized: [1, 21, 23, 14, 1] ACO RESULTS [1/290 vol./1520.496 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Mainz Hbf -> Frankfurt Hbf -> Mannheim Hbf --> Berlin Hbf [2/285 vol./1387.509 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [3/260 vol./ 947.647 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [4/225 vol./1738.161 km] Berlin Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Karlsruhe Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5593.813 km.