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: 21 customers
- Berlin Hbf (100 vol.)
- Düsseldorf Hbf (75 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (90 vol.)
- Dresden Hbf (90 vol.)
- Hamburg Hbf (80 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (40 vol.)
- Leipzig Hbf (85 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (60 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (85 vol.)
- Mannheim Hbf (80 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (85 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 1280.298 km
LOAD: 395 vol.
- Bremen Hbf | 40 vol.
- Hamburg Hbf | 80 vol.
- Berlin Hbf | 100 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 85 vol.
Tour 2
COST: 900.579 km
LOAD: 380 vol.
- Frankfurt Hbf | 30 vol.
- Köln Hbf | 85 vol.
- Aachen Hbf | 100 vol.
- Düsseldorf Hbf | 75 vol.
- Osnabrück Hbf | 90 vol.
Tour 3
COST: 1120.998 km
LOAD: 390 vol.
- Würzburg Hbf | 90 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 40 vol.
- Karlsruhe Hbf | 60 vol.
Tour 4
COST: 1218.04 km
LOAD: 385 vol.
- Mainz Hbf | 75 vol.
- Mannheim Hbf | 80 vol.
- Saarbrücken Hbf | 85 vol.
- Freiburg Hbf | 55 vol.
- Stuttgart Hbf | 90 vol.
Tour 5
COST: 362.286 km
LOAD: 55 vol.
- Hannover Hbf | 55 vol.
LOAD: 395 vol.
- Bremen Hbf | 40 vol.
- Hamburg Hbf | 80 vol.
- Berlin Hbf | 100 vol.
- Dresden Hbf | 90 vol.
- Leipzig Hbf | 85 vol.
LOAD: 380 vol.
- Frankfurt Hbf | 30 vol.
- Köln Hbf | 85 vol.
- Aachen Hbf | 100 vol.
- Düsseldorf Hbf | 75 vol.
- Osnabrück Hbf | 90 vol.
LOAD: 390 vol.
- Würzburg Hbf | 90 vol.
- Nürnberg Hbf | 100 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 40 vol.
- Karlsruhe Hbf | 60 vol.
LOAD: 385 vol.
- Mainz Hbf | 75 vol.
- Mannheim Hbf | 80 vol.
- Saarbrücken Hbf | 85 vol.
- Freiburg Hbf | 55 vol.
- Stuttgart Hbf | 90 vol.
LOAD: 55 vol.
- Hannover Hbf | 55 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: 1605 vol. | Vehicle capacity: 400 vol. Loads: [0, 100, 75, 30, 55, 100, 90, 90, 80, 100, 40, 85, 0, 100, 60, 40, 85, 80, 0, 75, 90, 85, 90, 55] ITERATION Generation: #1 Best cost: 6212.225 | Path: [0, 1, 7, 11, 4, 10, 3, 0, 22, 2, 16, 5, 15, 0, 17, 14, 6, 21, 23, 0, 19, 20, 13, 9, 0, 8, 0] Best cost: 5990.542 | Path: [0, 2, 16, 5, 21, 15, 0, 22, 10, 4, 8, 1, 3, 0, 19, 17, 14, 6, 20, 0, 11, 7, 13, 9, 0, 23, 0] Best cost: 5683.525 | Path: [0, 4, 10, 22, 16, 2, 3, 0, 20, 13, 6, 14, 15, 0, 17, 19, 21, 23, 9, 0, 11, 7, 1, 8, 0, 5, 0] Best cost: 5656.194 | Path: [0, 6, 14, 17, 3, 19, 15, 0, 22, 4, 10, 8, 1, 0, 20, 13, 9, 23, 0, 2, 16, 5, 21, 0, 11, 7, 0] Best cost: 5319.735 | Path: [0, 7, 11, 1, 8, 10, 0, 4, 22, 16, 2, 19, 0, 20, 13, 9, 15, 14, 0, 3, 17, 6, 23, 21, 0, 5, 0] Best cost: 5281.059 | Path: [0, 11, 7, 1, 8, 10, 0, 4, 22, 2, 16, 19, 0, 3, 17, 14, 6, 15, 9, 0, 20, 13, 23, 21, 0, 5, 0] Best cost: 5177.636 | Path: [0, 4, 10, 22, 2, 16, 3, 0, 20, 13, 9, 15, 14, 0, 19, 17, 21, 23, 6, 0, 11, 7, 1, 8, 0, 5, 0] Best cost: 5157.593 | Path: [0, 9, 15, 6, 14, 17, 3, 0, 4, 22, 10, 8, 1, 0, 16, 2, 5, 21, 23, 0, 20, 13, 7, 11, 0, 19, 0] Generation: #2 Best cost: 4936.784 | Path: [0, 11, 7, 1, 8, 10, 0, 20, 13, 9, 15, 14, 0, 22, 2, 16, 5, 3, 0, 19, 17, 6, 23, 21, 0, 4, 0] Generation: #4 Best cost: 4916.753 | Path: [0, 11, 7, 1, 8, 10, 0, 22, 2, 16, 5, 3, 0, 20, 13, 9, 15, 14, 0, 19, 17, 21, 23, 6, 0, 4, 0] OPTIMIZING each tour... Current: [[0, 11, 7, 1, 8, 10, 0], [0, 22, 2, 16, 5, 3, 0], [0, 20, 13, 9, 15, 14, 0], [0, 19, 17, 21, 23, 6, 0], [0, 4, 0]] [1] Cost: 1282.496 to 1280.298 | Optimized: [0, 10, 8, 1, 7, 11, 0] [2] Cost: 932.933 to 900.579 | Optimized: [0, 3, 16, 5, 2, 22, 0] ACO RESULTS [1/395 vol./1280.298 km] Kassel-Wilhelmshöhe -> Bremen Hbf -> Hamburg Hbf -> Berlin Hbf -> Dresden Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [2/380 vol./ 900.579 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Osnabrück Hbf --> Kassel-Wilhelmshöhe [3/390 vol./1120.998 km] Kassel-Wilhelmshöhe -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf --> Kassel-Wilhelmshöhe [4/385 vol./1218.040 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Stuttgart Hbf --> Kassel-Wilhelmshöhe [5/ 55 vol./ 362.286 km] Kassel-Wilhelmshöhe -> Hannover Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 5 tours | 4882.201 km.