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: 400 vol.
ACTIVE: 16 customers
- Berlin Hbf (55 vol.)
- Frankfurt Hbf (100 vol.)
- Aachen Hbf (35 vol.)
- Stuttgart Hbf (55 vol.)
- Dresden Hbf (90 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (95 vol.)
- Karlsruhe Hbf (30 vol.)
- Köln Hbf (90 vol.)
- Mannheim Hbf (40 vol.)
- Kiel Hbf (30 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (55 vol.)
- Saarbrücken Hbf (55 vol.)
- Osnabrück Hbf (35 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1793.276 km
LOAD: 380 vol.
- Dortmund Hbf | 20 vol.
- Osnabrück Hbf | 35 vol.
- Kiel Hbf | 30 vol.
- Berlin Hbf | 55 vol.
- Dresden Hbf | 90 vol.
- Nürnberg Hbf | 95 vol.
- Würzburg Hbf | 55 vol.
Tour 2
COST: 1224.119 km
LOAD: 370 vol.
- Mannheim Hbf | 40 vol.
- Karlsruhe Hbf | 30 vol.
- Stuttgart Hbf | 55 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 55 vol.
- Mainz Hbf | 55 vol.
- Frankfurt Hbf | 100 vol.
Tour 3
COST: 619.746 km
LOAD: 125 vol.
- Aachen Hbf | 35 vol.
- Köln Hbf | 90 vol.
LOAD: 380 vol.
- Dortmund Hbf | 20 vol.
- Osnabrück Hbf | 35 vol.
- Kiel Hbf | 30 vol.
- Berlin Hbf | 55 vol.
- Dresden Hbf | 90 vol.
- Nürnberg Hbf | 95 vol.
- Würzburg Hbf | 55 vol.
LOAD: 370 vol.
- Mannheim Hbf | 40 vol.
- Karlsruhe Hbf | 30 vol.
- Stuttgart Hbf | 55 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 55 vol.
- Mainz Hbf | 55 vol.
- Frankfurt Hbf | 100 vol.
LOAD: 125 vol.
- Aachen Hbf | 35 vol.
- Köln 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 875 vol. | Vehicle capacity: 400 vol. Loads: [0, 55, 0, 100, 0, 35, 55, 90, 0, 0, 0, 0, 20, 95, 30, 0, 90, 40, 30, 55, 55, 55, 35, 35] ITERATION Generation: #1 Best cost: 4500.050 | Path: [0, 1, 7, 13, 20, 3, 0, 22, 12, 16, 5, 19, 17, 14, 6, 23, 0, 21, 18, 0] Best cost: 4443.249 | Path: [0, 5, 16, 12, 22, 18, 1, 7, 17, 0, 20, 3, 19, 14, 6, 13, 0, 21, 23, 0] Best cost: 4431.796 | Path: [0, 6, 14, 17, 3, 19, 21, 23, 12, 0, 22, 16, 5, 20, 13, 7, 0, 18, 1, 0] Best cost: 4275.697 | Path: [0, 7, 1, 18, 22, 12, 16, 5, 17, 0, 3, 19, 21, 14, 6, 20, 23, 0, 13, 0] Best cost: 4236.147 | Path: [0, 5, 16, 12, 22, 18, 1, 7, 14, 0, 19, 3, 17, 21, 23, 6, 20, 0, 13, 0] Best cost: 4046.017 | Path: [0, 18, 1, 7, 13, 20, 19, 12, 0, 22, 16, 5, 21, 17, 14, 6, 23, 0, 3, 0] Best cost: 3966.940 | Path: [0, 19, 3, 17, 14, 6, 23, 21, 12, 0, 20, 13, 7, 1, 18, 22, 5, 0, 16, 0] Best cost: 3831.203 | Path: [0, 7, 1, 18, 22, 12, 16, 5, 17, 0, 20, 13, 6, 14, 23, 21, 19, 0, 3, 0] Generation: #2 Best cost: 3682.005 | Path: [0, 20, 13, 7, 1, 18, 22, 12, 0, 3, 19, 17, 14, 6, 23, 21, 0, 16, 5, 0] OPTIMIZING each tour... Current: [[0, 20, 13, 7, 1, 18, 22, 12, 0], [0, 3, 19, 17, 14, 6, 23, 21, 0], [0, 16, 5, 0]] [1] Cost: 1799.742 to 1793.276 | Optimized: [0, 12, 22, 18, 1, 7, 13, 20, 0] [2] Cost: 1261.975 to 1224.119 | Optimized: [0, 17, 14, 6, 23, 21, 19, 3, 0] [3] Cost: 620.288 to 619.746 | Optimized: [0, 5, 16, 0] ACO RESULTS [1/380 vol./1793.276 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Osnabrück Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [2/370 vol./1224.119 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/125 vol./ 619.746 km] Kassel-Wilhelmshöhe -> Aachen Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3637.141 km.