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 (75 vol.)
- Düsseldorf Hbf (50 vol.)
- Frankfurt Hbf (50 vol.)
- Hannover Hbf (50 vol.)
- Aachen Hbf (85 vol.)
- Stuttgart Hbf (100 vol.)
- Hamburg Hbf (60 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (20 vol.)
- Leipzig Hbf (85 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (90 vol.)
- Karlsruhe Hbf (80 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (95 vol.)
- Kiel Hbf (45 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (45 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1559.708 km
LOAD: 385 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 60 vol.
- Stuttgart Hbf | 100 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 35 vol.
- Dortmund Hbf | 20 vol.
Tour 2
COST: 1013.074 km
LOAD: 385 vol.
- Frankfurt Hbf | 50 vol.
- Mannheim Hbf | 95 vol.
- Saarbrücken Hbf | 45 vol.
- Aachen Hbf | 85 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 50 vol.
Tour 3
COST: 1327.422 km
LOAD: 335 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 45 vol.
- Berlin Hbf | 75 vol.
- Leipzig Hbf | 85 vol.
Tour 4
COST: 427.695 km
LOAD: 90 vol.
- Würzburg Hbf | 90 vol.
LOAD: 385 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 60 vol.
- Stuttgart Hbf | 100 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 35 vol.
- Dortmund Hbf | 20 vol.
LOAD: 385 vol.
- Frankfurt Hbf | 50 vol.
- Mannheim Hbf | 95 vol.
- Saarbrücken Hbf | 45 vol.
- Aachen Hbf | 85 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 50 vol.
LOAD: 335 vol.
- Hannover Hbf | 50 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 45 vol.
- Berlin Hbf | 75 vol.
- Leipzig Hbf | 85 vol.
LOAD: 90 vol.
- Würzburg 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: 1195 vol. | Vehicle capacity: 400 vol. Loads: [0, 75, 50, 50, 50, 85, 100, 0, 60, 60, 20, 85, 20, 90, 80, 0, 60, 95, 45, 0, 90, 45, 0, 35] ITERATION Generation: #1 Best cost: 5280.039 | Path: [0, 1, 11, 4, 10, 8, 18, 3, 0, 12, 2, 16, 5, 6, 14, 0, 20, 13, 9, 23, 17, 0, 21, 0] Best cost: 5270.361 | Path: [0, 3, 17, 14, 6, 23, 12, 10, 0, 4, 8, 18, 1, 11, 16, 0, 2, 5, 21, 9, 13, 0, 20, 0] Best cost: 5169.788 | Path: [0, 4, 10, 8, 18, 1, 11, 12, 21, 0, 20, 13, 6, 14, 23, 0, 3, 17, 16, 2, 5, 9, 0] Best cost: 5152.145 | Path: [0, 8, 18, 4, 10, 12, 2, 16, 5, 0, 3, 17, 14, 6, 21, 0, 20, 13, 9, 23, 11, 0, 1, 0] Best cost: 5147.260 | Path: [0, 9, 13, 20, 17, 21, 12, 0, 3, 14, 6, 23, 2, 16, 10, 0, 4, 8, 18, 1, 11, 5, 0] Best cost: 5009.918 | Path: [0, 12, 2, 16, 5, 3, 17, 23, 0, 4, 10, 8, 18, 1, 11, 9, 0, 20, 13, 6, 14, 0, 21, 0] Best cost: 4990.497 | Path: [0, 18, 8, 10, 4, 2, 16, 12, 5, 0, 3, 17, 14, 6, 23, 0, 20, 13, 9, 11, 1, 0, 21, 0] Best cost: 4871.282 | Path: [0, 20, 3, 17, 14, 23, 21, 0, 4, 10, 8, 18, 12, 2, 16, 5, 0, 13, 9, 6, 11, 0, 1, 0] Best cost: 4822.221 | Path: [0, 2, 16, 5, 12, 4, 10, 8, 18, 0, 3, 17, 14, 6, 23, 0, 20, 13, 9, 11, 1, 0, 21, 0] Best cost: 4570.302 | Path: [0, 17, 14, 6, 13, 23, 0, 12, 2, 16, 5, 21, 3, 20, 0, 4, 10, 8, 18, 1, 11, 9, 0] Best cost: 4561.600 | Path: [0, 12, 2, 16, 5, 21, 17, 23, 0, 3, 20, 13, 9, 6, 0, 4, 10, 8, 18, 1, 11, 0, 14, 0] Best cost: 4467.250 | Path: [0, 8, 18, 10, 4, 3, 17, 14, 0, 12, 2, 16, 5, 21, 23, 6, 0, 20, 13, 9, 11, 1, 0] Best cost: 4449.440 | Path: [0, 3, 17, 14, 6, 9, 0, 12, 2, 16, 5, 21, 23, 20, 0, 4, 10, 8, 18, 1, 11, 0, 13, 0] Generation: #2 Best cost: 4444.421 | Path: [0, 9, 6, 14, 17, 3, 0, 12, 2, 16, 5, 21, 23, 20, 0, 4, 10, 8, 18, 1, 11, 0, 13, 0] Best cost: 4327.899 | Path: [0, 13, 9, 6, 14, 23, 12, 0, 3, 17, 21, 5, 16, 2, 0, 4, 10, 8, 18, 1, 11, 0, 20, 0] OPTIMIZING each tour... Current: [[0, 13, 9, 6, 14, 23, 12, 0], [0, 3, 17, 21, 5, 16, 2, 0], [0, 4, 10, 8, 18, 1, 11, 0], [0, 20, 0]] No changes made. ACO RESULTS [1/385 vol./1559.708 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Dortmund Hbf --> Kassel-Wilhelmshöhe [2/385 vol./1013.074 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf --> Kassel-Wilhelmshöhe [3/335 vol./1327.422 km] Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [4/ 90 vol./ 427.695 km] Kassel-Wilhelmshöhe -> Würzburg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4327.899 km.