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
- Berlin Hbf (100 vol.)
- Düsseldorf Hbf (90 vol.)
- Frankfurt Hbf (80 vol.)
- Stuttgart Hbf (55 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (45 vol.)
- München Hbf (50 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (65 vol.)
- Dortmund Hbf (100 vol.)
- Nürnberg Hbf (90 vol.)
- Ulm Hbf (30 vol.)
- Köln Hbf (25 vol.)
- Kiel Hbf (35 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (80 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1163.46 km
LOAD: 400 vol.
- Würzburg Hbf | 50 vol.
- Frankfurt Hbf | 80 vol.
- Köln Hbf | 25 vol.
- Düsseldorf Hbf | 90 vol.
- Dortmund Hbf | 100 vol.
- Bremen Hbf | 55 vol.
Tour 2
COST: 1435.06 km
LOAD: 400 vol.
- Osnabrück Hbf | 80 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 35 vol.
- Berlin Hbf | 100 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 65 vol.
Tour 3
COST: 1507.032 km
LOAD: 365 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 55 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 60 vol.
LOAD: 400 vol.
- Würzburg Hbf | 50 vol.
- Frankfurt Hbf | 80 vol.
- Köln Hbf | 25 vol.
- Düsseldorf Hbf | 90 vol.
- Dortmund Hbf | 100 vol.
- Bremen Hbf | 55 vol.
LOAD: 400 vol.
- Osnabrück Hbf | 80 vol.
- Hamburg Hbf | 45 vol.
- Kiel Hbf | 35 vol.
- Berlin Hbf | 100 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 65 vol.
LOAD: 365 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 55 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken 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: 1165 vol. | Vehicle capacity: 400 vol. Loads: [0, 100, 90, 80, 0, 0, 55, 75, 45, 50, 55, 65, 100, 90, 0, 30, 25, 0, 35, 0, 50, 60, 80, 80] ITERATION Generation: #1 Best cost: 4749.540 | Path: [0, 1, 11, 7, 13, 20, 0, 12, 2, 16, 22, 10, 8, 0, 3, 21, 23, 6, 15, 9, 18, 0] Best cost: 4681.921 | Path: [0, 3, 20, 13, 9, 15, 6, 16, 0, 22, 10, 8, 18, 1, 11, 0, 12, 2, 21, 23, 0, 7, 0] Best cost: 4400.552 | Path: [0, 7, 11, 1, 18, 8, 10, 16, 0, 12, 2, 22, 3, 20, 0, 13, 9, 15, 6, 23, 21, 0] Best cost: 4353.933 | Path: [0, 12, 2, 16, 3, 20, 6, 0, 22, 10, 8, 18, 1, 7, 0, 11, 13, 9, 15, 21, 23, 0] Best cost: 4328.428 | Path: [0, 21, 6, 15, 9, 13, 20, 11, 0, 3, 23, 16, 2, 12, 0, 22, 10, 8, 18, 1, 7, 0] Best cost: 4309.925 | Path: [0, 11, 7, 1, 18, 8, 10, 16, 0, 12, 2, 22, 3, 20, 0, 13, 9, 15, 6, 23, 21, 0] Best cost: 4250.185 | Path: [0, 22, 10, 8, 18, 1, 7, 0, 12, 2, 16, 3, 20, 6, 0, 11, 13, 9, 15, 23, 21, 0] Best cost: 4105.552 | Path: [0, 20, 3, 16, 2, 12, 10, 0, 22, 8, 18, 1, 7, 11, 0, 13, 9, 15, 6, 23, 21, 0] OPTIMIZING each tour... Current: [[0, 20, 3, 16, 2, 12, 10, 0], [0, 22, 8, 18, 1, 7, 11, 0], [0, 13, 9, 15, 6, 23, 21, 0]] No changes made. ACO RESULTS [1/400 vol./1163.460 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Frankfurt Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Bremen Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1435.060 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/365 vol./1507.032 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4105.552 km.