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
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (90 vol.)
- Aachen Hbf (55 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (80 vol.)
- Hamburg Hbf (95 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (70 vol.)
- Leipzig Hbf (75 vol.)
- Dortmund Hbf (70 vol.)
- Nürnberg Hbf (45 vol.)
- Karlsruhe Hbf (100 vol.)
- Ulm Hbf (35 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (75 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (40 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (95 vol.)
Tour 1
COST: 1468.729 km
LOAD: 390 vol.
- Leipzig Hbf | 75 vol.
- Dresden Hbf | 80 vol.
- Nürnberg Hbf | 45 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 60 vol.
Tour 2
COST: 923.785 km
LOAD: 370 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 90 vol.
- Aachen Hbf | 55 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 90 vol.
- Würzburg Hbf | 40 vol.
Tour 3
COST: 929.97 km
LOAD: 330 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 75 vol.
- Bremen Hbf | 70 vol.
- Osnabrück Hbf | 90 vol.
Tour 4
COST: 934.8 km
LOAD: 270 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg Hbf | 95 vol.
LOAD: 390 vol.
- Leipzig Hbf | 75 vol.
- Dresden Hbf | 80 vol.
- Nürnberg Hbf | 45 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 35 vol.
- Stuttgart Hbf | 60 vol.
LOAD: 370 vol.
- Dortmund Hbf | 70 vol.
- Düsseldorf Hbf | 90 vol.
- Aachen Hbf | 55 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 90 vol.
- Würzburg Hbf | 40 vol.
LOAD: 330 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 75 vol.
- Bremen Hbf | 70 vol.
- Osnabrück Hbf | 90 vol.
LOAD: 270 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 100 vol.
- Freiburg 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: 1360 vol. | Vehicle capacity: 400 vol. Loads: [0, 0, 90, 90, 0, 55, 60, 80, 95, 95, 70, 75, 70, 45, 100, 35, 0, 75, 75, 25, 40, 0, 90, 95] ITERATION Generation: #1 Best cost: 5315.956 | Path: [0, 2, 12, 5, 19, 3, 20, 0, 22, 10, 8, 18, 13, 0, 17, 14, 6, 15, 9, 0, 11, 7, 23, 0] Best cost: 5041.414 | Path: [0, 3, 19, 17, 14, 6, 15, 0, 12, 2, 5, 22, 10, 0, 20, 13, 9, 7, 11, 0, 8, 18, 23, 0] Best cost: 4812.344 | Path: [0, 10, 22, 12, 2, 5, 19, 0, 3, 17, 14, 6, 15, 20, 0, 11, 7, 9, 13, 23, 0, 8, 18, 0] Best cost: 4692.142 | Path: [0, 23, 14, 6, 15, 9, 0, 22, 12, 2, 5, 19, 20, 0, 3, 17, 13, 11, 7, 0, 18, 8, 10, 0] Best cost: 4587.321 | Path: [0, 20, 13, 9, 15, 6, 14, 19, 0, 3, 17, 23, 5, 12, 0, 22, 10, 8, 18, 0, 2, 11, 7, 0] Best cost: 4530.863 | Path: [0, 20, 13, 9, 15, 6, 14, 19, 0, 12, 2, 5, 17, 3, 0, 22, 10, 8, 18, 0, 11, 7, 23, 0] Best cost: 4403.293 | Path: [0, 22, 12, 2, 5, 19, 20, 0, 11, 7, 13, 9, 15, 6, 0, 3, 17, 14, 23, 0, 10, 8, 18, 0] Best cost: 4315.296 | Path: [0, 11, 7, 13, 9, 15, 6, 0, 12, 2, 5, 3, 19, 20, 0, 22, 10, 8, 18, 0, 17, 14, 23, 0] Generation: #2 Best cost: 4264.835 | Path: [0, 11, 7, 13, 9, 15, 6, 0, 12, 2, 5, 19, 3, 20, 0, 22, 10, 8, 18, 0, 17, 14, 23, 0] OPTIMIZING each tour... Current: [[0, 11, 7, 13, 9, 15, 6, 0], [0, 12, 2, 5, 19, 3, 20, 0], [0, 22, 10, 8, 18, 0], [0, 17, 14, 23, 0]] [3] Cost: 937.521 to 929.970 | Optimized: [0, 8, 18, 10, 22, 0] ACO RESULTS [1/390 vol./1468.729 km] Kassel-Wilhelmshöhe -> Leipzig Hbf -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf --> Kassel-Wilhelmshöhe [2/370 vol./ 923.785 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [3/330 vol./ 929.970 km] Kassel-Wilhelmshöhe -> Hamburg Hbf -> Kiel Hbf -> Bremen Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe [4/270 vol./ 934.800 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4257.284 km.