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: 18 customers
- Düsseldorf Hbf (45 vol.)
- Frankfurt Hbf (25 vol.)
- Hannover Hbf (25 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (80 vol.)
- Hamburg Hbf (50 vol.)
- München Hbf (45 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (65 vol.)
- Köln Hbf (20 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (35 vol.)
- Osnabrück Hbf (100 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1172.511 km
LOAD: 395 vol.
- Hannover Hbf | 25 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 90 vol.
- Osnabrück Hbf | 100 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 45 vol.
Tour 2
COST: 1668.324 km
LOAD: 400 vol.
- Würzburg Hbf | 35 vol.
- Frankfurt Hbf | 25 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 80 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 65 vol.
- München Hbf | 45 vol.
- Nürnberg Hbf | 25 vol.
- Dresden Hbf | 80 vol.
Tour 3
COST: 1152.391 km
LOAD: 155 vol.
- Köln Hbf | 20 vol.
- Mainz Hbf | 75 vol.
- Freiburg Hbf | 60 vol.
LOAD: 395 vol.
- Hannover Hbf | 25 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 90 vol.
- Osnabrück Hbf | 100 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 45 vol.
LOAD: 400 vol.
- Würzburg Hbf | 35 vol.
- Frankfurt Hbf | 25 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 80 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 65 vol.
- München Hbf | 45 vol.
- Nürnberg Hbf | 25 vol.
- Dresden Hbf | 80 vol.
LOAD: 155 vol.
- Köln Hbf | 20 vol.
- Mainz Hbf | 75 vol.
- Freiburg Hbf | 60 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: 950 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 45, 25, 25, 0, 20, 80, 50, 45, 0, 0, 85, 25, 80, 65, 20, 25, 90, 75, 35, 0, 100, 60] ITERATION Generation: #1 Best cost: 4634.154 | Path: [0, 2, 16, 12, 22, 4, 8, 20, 13, 0, 3, 19, 17, 14, 6, 15, 9, 23, 0, 7, 18, 0] Best cost: 4535.482 | Path: [0, 3, 19, 17, 14, 6, 15, 9, 13, 20, 0, 12, 2, 16, 22, 4, 8, 23, 0, 7, 18, 0] Best cost: 4497.115 | Path: [0, 4, 22, 12, 2, 16, 19, 3, 17, 0, 20, 13, 9, 15, 6, 14, 23, 8, 0, 7, 18, 0] Best cost: 4409.814 | Path: [0, 7, 13, 20, 3, 19, 17, 14, 6, 16, 0, 2, 12, 22, 4, 8, 18, 0, 23, 15, 9, 0] Best cost: 4330.516 | Path: [0, 3, 19, 17, 14, 6, 15, 9, 13, 20, 0, 12, 22, 4, 8, 18, 2, 0, 16, 23, 7, 0] Best cost: 4268.190 | Path: [0, 4, 8, 18, 22, 12, 2, 0, 20, 19, 3, 17, 14, 6, 15, 9, 13, 0, 16, 23, 7, 0] Best cost: 4263.056 | Path: [0, 13, 9, 15, 6, 14, 17, 3, 19, 20, 0, 4, 8, 18, 22, 12, 2, 0, 16, 23, 7, 0] Best cost: 4173.476 | Path: [0, 18, 8, 4, 22, 12, 2, 0, 20, 13, 9, 15, 6, 14, 17, 19, 3, 0, 16, 23, 7, 0] Best cost: 4119.897 | Path: [0, 4, 8, 18, 22, 12, 2, 0, 3, 19, 17, 14, 6, 15, 9, 13, 20, 0, 16, 23, 7, 0] Best cost: 4109.803 | Path: [0, 22, 12, 16, 2, 19, 3, 17, 6, 0, 20, 13, 9, 15, 14, 23, 7, 0, 4, 8, 18, 0] Best cost: 4047.971 | Path: [0, 22, 12, 2, 16, 19, 3, 17, 6, 0, 20, 13, 9, 15, 14, 23, 7, 0, 4, 8, 18, 0] Generation: #9 Best cost: 4018.914 | Path: [0, 4, 8, 18, 22, 12, 2, 0, 7, 20, 13, 9, 15, 6, 14, 17, 3, 0, 16, 19, 23, 0] OPTIMIZING each tour... Current: [[0, 4, 8, 18, 22, 12, 2, 0], [0, 7, 20, 13, 9, 15, 6, 14, 17, 3, 0], [0, 16, 19, 23, 0]] [2] Cost: 1694.012 to 1668.324 | Optimized: [0, 20, 3, 17, 14, 6, 15, 9, 13, 7, 0] ACO RESULTS [1/395 vol./1172.511 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf -> Osnabrück Hbf -> Dortmund Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1668.324 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf -> München Hbf -> Nürnberg Hbf -> Dresden Hbf --> Kassel-Wilhelmshöhe [3/155 vol./1152.391 km] Kassel-Wilhelmshöhe -> Köln Hbf -> Mainz Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3993.226 km.