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: 14 customers
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (100 vol.)
- Stuttgart Hbf (30 vol.)
- Hamburg Hbf (100 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (40 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (80 vol.)
- Köln Hbf (20 vol.)
- Kiel Hbf (95 vol.)
- Mainz Hbf (65 vol.)
- Saarbrücken Hbf (20 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1967.37 km
LOAD: 300 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 20 vol.
- Mainz Hbf | 65 vol.
- Köln Hbf | 20 vol.
- Dortmund Hbf | 40 vol.
Tour 2
COST: 1454.294 km
LOAD: 295 vol.
- Leipzig Hbf | 35 vol.
- Nürnberg Hbf | 100 vol.
- Frankfurt Hbf | 70 vol.
- Osnabrück Hbf | 90 vol.
Tour 3
COST: 881.934 km
LOAD: 295 vol.
- Hannover Hbf | 100 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 95 vol.
LOAD: 300 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 20 vol.
- Mainz Hbf | 65 vol.
- Köln Hbf | 20 vol.
- Dortmund Hbf | 40 vol.
LOAD: 295 vol.
- Leipzig Hbf | 35 vol.
- Nürnberg Hbf | 100 vol.
- Frankfurt Hbf | 70 vol.
- Osnabrück Hbf | 90 vol.
LOAD: 295 vol.
- Hannover Hbf | 100 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 95 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: 890 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 0, 70, 100, 0, 30, 0, 100, 0, 0, 35, 40, 100, 80, 0, 20, 0, 95, 65, 0, 20, 90, 45] ITERATION Generation: #1 Best cost: 6274.977 | Path: [1, 3, 19, 21, 14, 6, 16, 1, 11, 4, 22, 12, 1, 8, 18, 13, 1, 23, 1] Best cost: 5928.028 | Path: [1, 6, 14, 3, 19, 21, 16, 1, 11, 13, 22, 12, 1, 4, 8, 18, 1, 23, 1] Best cost: 5134.580 | Path: [1, 8, 18, 4, 1, 11, 13, 6, 14, 23, 1, 12, 16, 3, 19, 21, 1, 22, 1] Best cost: 5101.493 | Path: [1, 4, 8, 18, 1, 11, 13, 6, 14, 23, 1, 21, 19, 3, 16, 12, 1, 22, 1] Best cost: 4622.136 | Path: [1, 12, 16, 19, 3, 14, 21, 1, 11, 13, 6, 23, 22, 1, 8, 18, 4, 1] Best cost: 4592.181 | Path: [1, 18, 8, 4, 1, 11, 19, 3, 14, 6, 16, 1, 13, 23, 21, 12, 22, 1] Best cost: 4517.045 | Path: [1, 18, 8, 4, 1, 11, 22, 12, 16, 19, 21, 6, 1, 13, 14, 23, 3, 1] Best cost: 4336.757 | Path: [1, 6, 14, 23, 21, 19, 16, 12, 1, 8, 18, 4, 1, 11, 13, 3, 22, 1] Best cost: 4336.757 | Path: [1, 6, 14, 23, 21, 19, 16, 12, 1, 11, 13, 3, 22, 1, 8, 18, 4, 1] Generation: #2 Best cost: 4303.598 | Path: [1, 6, 14, 23, 21, 19, 16, 12, 1, 11, 13, 3, 22, 1, 4, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 6, 14, 23, 21, 19, 16, 12, 1], [1, 11, 13, 3, 22, 1], [1, 4, 8, 18, 1]] No changes made. ACO RESULTS [1/300 vol./1967.370 km] Berlin Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Köln Hbf -> Dortmund Hbf --> Berlin Hbf [2/295 vol./1454.294 km] Berlin Hbf -> Leipzig Hbf -> Nürnberg Hbf -> Frankfurt Hbf -> Osnabrück Hbf --> Berlin Hbf [3/295 vol./ 881.934 km] Berlin Hbf -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4303.598 km.