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: 19 customers
- Berlin Hbf (100 vol.)
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (30 vol.)
- Stuttgart Hbf (100 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (25 vol.)
- München Hbf (90 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (95 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (65 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (25 vol.)
- Mainz Hbf (90 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (25 vol.)
- Freiburg Hbf (30 vol.)
Tour 1
COST: 1229.676 km
LOAD: 400 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 90 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 30 vol.
- Saarbrücken Hbf | 50 vol.
- Köln Hbf | 95 vol.
Tour 2
COST: 1508.662 km
LOAD: 400 vol.
- Düsseldorf Hbf | 35 vol.
- Osnabrück Hbf | 25 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 25 vol.
- Berlin Hbf | 100 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 95 vol.
Tour 3
COST: 1295.407 km
LOAD: 395 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 90 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 100 vol.
- Dortmund Hbf | 60 vol.
LOAD: 400 vol.
- Frankfurt Hbf | 30 vol.
- Mainz Hbf | 90 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 30 vol.
- Saarbrücken Hbf | 50 vol.
- Köln Hbf | 95 vol.
LOAD: 400 vol.
- Düsseldorf Hbf | 35 vol.
- Osnabrück Hbf | 25 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 25 vol.
- Berlin Hbf | 100 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 95 vol.
LOAD: 395 vol.
- Nürnberg Hbf | 80 vol.
- München Hbf | 90 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 100 vol.
- Dortmund 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: 1195 vol. | Vehicle capacity: 400 vol. Loads: [0, 100, 35, 30, 0, 0, 100, 85, 25, 90, 35, 95, 60, 80, 80, 65, 95, 25, 0, 90, 0, 50, 25, 30] ITERATION Generation: #1 Best cost: 5651.760 | Path: [0, 1, 11, 7, 13, 17, 0, 22, 12, 2, 16, 19, 3, 21, 0, 10, 8, 6, 14, 23, 15, 0, 9, 0] Best cost: 4879.230 | Path: [0, 2, 16, 12, 22, 10, 8, 1, 17, 0, 3, 19, 14, 6, 15, 23, 0, 11, 7, 13, 9, 21, 0] Best cost: 4557.102 | Path: [0, 9, 15, 6, 14, 17, 3, 0, 11, 7, 1, 8, 10, 22, 2, 0, 12, 16, 19, 21, 23, 0, 13, 0] Best cost: 4554.398 | Path: [0, 23, 14, 17, 3, 19, 21, 16, 0, 12, 2, 22, 10, 8, 1, 7, 0, 13, 9, 15, 6, 0, 11, 0] Best cost: 4445.479 | Path: [0, 13, 9, 15, 6, 17, 3, 0, 12, 2, 16, 19, 14, 23, 0, 22, 10, 8, 1, 11, 7, 0, 21, 0] Best cost: 4350.467 | Path: [0, 13, 9, 15, 6, 17, 3, 0, 12, 2, 16, 19, 14, 23, 0, 22, 10, 8, 1, 7, 11, 0, 21, 0] Best cost: 4337.045 | Path: [0, 17, 14, 23, 21, 19, 3, 16, 0, 22, 10, 8, 1, 7, 11, 2, 0, 12, 6, 15, 9, 13, 0] OPTIMIZING each tour... Current: [[0, 17, 14, 23, 21, 19, 3, 16, 0], [0, 22, 10, 8, 1, 7, 11, 2, 0], [0, 12, 6, 15, 9, 13, 0]] [1] Cost: 1301.318 to 1229.676 | Optimized: [0, 3, 19, 17, 14, 23, 21, 16, 0] [2] Cost: 1716.055 to 1508.662 | Optimized: [0, 2, 22, 10, 8, 1, 7, 11, 0] [3] Cost: 1319.672 to 1295.407 | Optimized: [0, 13, 9, 15, 6, 12, 0] ACO RESULTS [1/400 vol./1229.676 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1508.662 km] Kassel-Wilhelmshöhe -> Düsseldorf Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/395 vol./1295.407 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4033.745 km.