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: 15 customers
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (30 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (45 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (90 vol.)
- Leipzig Hbf (90 vol.)
- Nürnberg Hbf (65 vol.)
- Karlsruhe Hbf (70 vol.)
- Ulm Hbf (70 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (40 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1760.551 km
LOAD: 395 vol.
- Leipzig Hbf | 90 vol.
- Dresden Hbf | 35 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 70 vol.
- Freiburg Hbf | 35 vol.
Tour 2
COST: 1142.893 km
LOAD: 365 vol.
- Düsseldorf Hbf | 90 vol.
- Aachen Hbf | 30 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 70 vol.
- Stuttgart Hbf | 70 vol.
- Frankfurt Hbf | 30 vol.
Tour 3
COST: 924.339 km
LOAD: 175 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 40 vol.
- Bremen Hbf | 90 vol.
LOAD: 395 vol.
- Leipzig Hbf | 90 vol.
- Dresden Hbf | 35 vol.
- Nürnberg Hbf | 65 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 70 vol.
- Freiburg Hbf | 35 vol.
LOAD: 365 vol.
- Düsseldorf Hbf | 90 vol.
- Aachen Hbf | 30 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 70 vol.
- Stuttgart Hbf | 70 vol.
- Frankfurt Hbf | 30 vol.
LOAD: 175 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 40 vol.
- Bremen 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: 935 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 90, 30, 0, 30, 70, 35, 45, 100, 90, 90, 0, 65, 70, 70, 0, 75, 40, 0, 0, 0, 0, 35] ITERATION Generation: #1 Best cost: 4644.945 | Path: [0, 2, 5, 17, 14, 6, 3, 23, 0, 11, 7, 13, 9, 15, 18, 0, 10, 8, 0] Best cost: 4406.146 | Path: [0, 3, 17, 14, 6, 15, 13, 0, 2, 5, 10, 8, 18, 11, 0, 7, 9, 23, 0] Best cost: 3981.794 | Path: [0, 7, 11, 13, 9, 15, 23, 0, 3, 17, 14, 6, 2, 5, 0, 18, 8, 10, 0] Best cost: 3909.872 | Path: [0, 7, 11, 13, 9, 15, 23, 0, 3, 17, 14, 6, 5, 2, 0, 10, 8, 18, 0] Best cost: 3849.460 | Path: [0, 11, 7, 13, 9, 15, 3, 0, 2, 5, 17, 14, 6, 23, 0, 10, 8, 18, 0] Best cost: 3844.138 | Path: [0, 11, 7, 13, 9, 15, 23, 0, 3, 17, 14, 6, 5, 2, 0, 10, 8, 18, 0] Generation: #2 Best cost: 3840.922 | Path: [0, 11, 7, 13, 9, 15, 23, 0, 2, 5, 17, 14, 6, 3, 0, 10, 8, 18, 0] Best cost: 3833.617 | Path: [0, 11, 7, 13, 9, 15, 23, 0, 2, 5, 3, 17, 14, 6, 0, 8, 18, 10, 0] Generation: #3 Best cost: 3827.783 | Path: [0, 11, 7, 13, 9, 15, 23, 0, 2, 5, 17, 14, 6, 3, 0, 8, 18, 10, 0] OPTIMIZING each tour... Current: [[0, 11, 7, 13, 9, 15, 23, 0], [0, 2, 5, 17, 14, 6, 3, 0], [0, 8, 18, 10, 0]] No changes made. ACO RESULTS [1/395 vol./1760.551 km] Kassel-Wilhelmshöhe -> Leipzig Hbf -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [2/365 vol./1142.893 km] Kassel-Wilhelmshöhe -> Düsseldorf Hbf -> Aachen Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/175 vol./ 924.339 km] Kassel-Wilhelmshöhe -> Hamburg Hbf -> Kiel Hbf -> Bremen Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3827.783 km.