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: 16 customers
- Berlin Hbf (95 vol.)
- Düsseldorf Hbf (60 vol.)
- Frankfurt Hbf (25 vol.)
- Hannover Hbf (35 vol.)
- Stuttgart Hbf (35 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (25 vol.)
- Nürnberg Hbf (85 vol.)
- Ulm Hbf (100 vol.)
- Köln Hbf (85 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (40 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1392.976 km
LOAD: 385 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 35 vol.
- Freiburg Hbf | 85 vol.
Tour 2
COST: 1045.965 km
LOAD: 385 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 55 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 85 vol.
- Mainz Hbf | 75 vol.
- Frankfurt Hbf | 25 vol.
Tour 3
COST: 1236.11 km
LOAD: 220 vol.
- Hannover Hbf | 35 vol.
- Kiel Hbf | 65 vol.
- Berlin Hbf | 95 vol.
- Leipzig Hbf | 25 vol.
LOAD: 385 vol.
- Würzburg Hbf | 40 vol.
- Nürnberg Hbf | 85 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 35 vol.
- Freiburg Hbf | 85 vol.
LOAD: 385 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 55 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 85 vol.
- Mainz Hbf | 75 vol.
- Frankfurt Hbf | 25 vol.
LOAD: 220 vol.
- Hannover Hbf | 35 vol.
- Kiel Hbf | 65 vol.
- Berlin Hbf | 95 vol.
- Leipzig Hbf | 25 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: 990 vol. | Vehicle capacity: 400 vol. Loads: [0, 95, 60, 25, 35, 0, 35, 0, 0, 40, 55, 25, 0, 85, 0, 100, 85, 0, 65, 75, 40, 0, 85, 85] ITERATION Generation: #1 Best cost: 4762.957 | Path: [0, 1, 11, 4, 10, 22, 16, 0, 19, 3, 20, 13, 9, 15, 6, 0, 2, 23, 18, 0] Best cost: 4372.394 | Path: [0, 3, 19, 20, 6, 15, 9, 13, 0, 2, 16, 22, 10, 4, 18, 0, 11, 1, 23, 0] Best cost: 4324.718 | Path: [0, 4, 10, 22, 2, 16, 19, 0, 20, 13, 15, 6, 9, 23, 0, 3, 11, 1, 18, 0] Best cost: 3939.492 | Path: [0, 6, 15, 9, 13, 20, 3, 19, 0, 4, 22, 10, 18, 1, 11, 0, 16, 2, 23, 0] Best cost: 3859.763 | Path: [0, 19, 3, 20, 13, 9, 15, 6, 0, 22, 4, 10, 18, 1, 11, 0, 2, 16, 23, 0] Best cost: 3811.084 | Path: [0, 20, 13, 9, 15, 6, 3, 19, 0, 4, 22, 10, 18, 1, 11, 0, 2, 16, 23, 0] Best cost: 3700.315 | Path: [0, 23, 6, 15, 9, 13, 20, 0, 3, 19, 16, 2, 22, 10, 0, 4, 18, 1, 11, 0] Generation: #3 Best cost: 3683.114 | Path: [0, 20, 13, 9, 15, 6, 23, 0, 3, 19, 16, 2, 22, 10, 0, 4, 18, 1, 11, 0] OPTIMIZING each tour... Current: [[0, 20, 13, 9, 15, 6, 23, 0], [0, 3, 19, 16, 2, 22, 10, 0], [0, 4, 18, 1, 11, 0]] [2] Cost: 1054.028 to 1045.965 | Optimized: [0, 22, 10, 2, 16, 19, 3, 0] ACO RESULTS [1/385 vol./1392.976 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf --> Kassel-Wilhelmshöhe [2/385 vol./1045.965 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Düsseldorf Hbf -> Köln Hbf -> Mainz Hbf -> Frankfurt Hbf --> Kassel-Wilhelmshöhe [3/220 vol./1236.110 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Kiel Hbf -> Berlin Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3675.051 km.