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
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (65 vol.)
- Hannover Hbf (80 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (55 vol.)
- Hamburg Hbf (40 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (30 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (70 vol.)
- Mainz Hbf (100 vol.)
- Saarbrücken Hbf (65 vol.)
- Osnabrück Hbf (65 vol.)
Tour 1
COST: 1229.885 km
LOAD: 375 vol.
- Frankfurt Hbf | 65 vol.
- Mainz Hbf | 100 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 30 vol.
- Stuttgart Hbf | 55 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 20 vol.
Tour 2
COST: 1167.979 km
LOAD: 385 vol.
- Hannover Hbf | 80 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 70 vol.
- Osnabrück Hbf | 65 vol.
- Düsseldorf Hbf | 65 vol.
- Dortmund Hbf | 65 vol.
Tour 3
COST: 951.368 km
LOAD: 210 vol.
- Saarbrücken Hbf | 65 vol.
- Aachen Hbf | 50 vol.
- Köln Hbf | 95 vol.
LOAD: 375 vol.
- Frankfurt Hbf | 65 vol.
- Mainz Hbf | 100 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 30 vol.
- Stuttgart Hbf | 55 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 20 vol.
LOAD: 385 vol.
- Hannover Hbf | 80 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 70 vol.
- Osnabrück Hbf | 65 vol.
- Düsseldorf Hbf | 65 vol.
- Dortmund Hbf | 65 vol.
LOAD: 210 vol.
- Saarbrücken Hbf | 65 vol.
- Aachen Hbf | 50 vol.
- Köln 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 970 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 65, 65, 80, 50, 55, 0, 40, 0, 0, 20, 65, 85, 30, 0, 95, 20, 70, 100, 0, 65, 65, 0] ITERATION Generation: #1 Best cost: 4104.522 | Path: [0, 2, 16, 5, 12, 22, 8, 11, 0, 19, 3, 17, 14, 6, 13, 0, 4, 18, 21, 0] Best cost: 3971.363 | Path: [0, 3, 19, 17, 14, 6, 13, 11, 0, 12, 2, 16, 5, 22, 8, 0, 4, 18, 21, 0] Best cost: 3883.070 | Path: [0, 4, 22, 12, 2, 16, 17, 0, 3, 19, 21, 14, 6, 13, 0, 11, 18, 8, 5, 0] Best cost: 3691.971 | Path: [0, 8, 18, 4, 22, 12, 2, 0, 3, 19, 17, 14, 6, 21, 5, 0, 16, 13, 11, 0] Best cost: 3584.988 | Path: [0, 12, 2, 16, 5, 21, 14, 17, 0, 22, 4, 8, 18, 11, 13, 0, 19, 3, 6, 0] Best cost: 3426.814 | Path: [0, 18, 8, 4, 22, 12, 2, 0, 3, 19, 17, 14, 6, 13, 11, 0, 16, 5, 21, 0] Best cost: 3396.420 | Path: [0, 22, 12, 2, 16, 5, 17, 14, 0, 3, 19, 21, 6, 13, 11, 0, 4, 8, 18, 0] Best cost: 3357.141 | Path: [0, 4, 8, 18, 22, 12, 2, 0, 3, 19, 17, 14, 6, 13, 11, 0, 16, 5, 21, 0] Best cost: 3349.232 | Path: [0, 3, 19, 17, 14, 6, 13, 11, 0, 4, 8, 18, 22, 2, 12, 0, 21, 5, 16, 0] OPTIMIZING each tour... Current: [[0, 3, 19, 17, 14, 6, 13, 11, 0], [0, 4, 8, 18, 22, 2, 12, 0], [0, 21, 5, 16, 0]] No changes made. ACO RESULTS [1/375 vol./1229.885 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/385 vol./1167.979 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf -> Osnabrück Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [3/210 vol./ 951.368 km] Kassel-Wilhelmshöhe -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3349.232 km.