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 (20 vol.)
- Frankfurt Hbf (25 vol.)
- Hannover Hbf (80 vol.)
- Aachen Hbf (95 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (90 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (50 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (75 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (70 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (80 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1513.827 km
LOAD: 395 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 70 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 60 vol.
- Saarbrücken Hbf | 70 vol.
Tour 2
COST: 1153.389 km
LOAD: 400 vol.
- Frankfurt Hbf | 25 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 95 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 45 vol.
- Hannover Hbf | 80 vol.
Tour 3
COST: 1857.218 km
LOAD: 400 vol.
- Mainz Hbf | 20 vol.
- Würzburg Hbf | 70 vol.
- Nürnberg Hbf | 100 vol.
- Leipzig Hbf | 50 vol.
- Dresden Hbf | 90 vol.
- Berlin Hbf | 20 vol.
- Kiel Hbf | 50 vol.
LOAD: 395 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 70 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 60 vol.
- Saarbrücken Hbf | 70 vol.
LOAD: 400 vol.
- Frankfurt Hbf | 25 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 95 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 45 vol.
- Hannover Hbf | 80 vol.
LOAD: 400 vol.
- Mainz Hbf | 20 vol.
- Würzburg Hbf | 70 vol.
- Nürnberg Hbf | 100 vol.
- Leipzig Hbf | 50 vol.
- Dresden Hbf | 90 vol.
- Berlin Hbf | 20 vol.
- Kiel Hbf | 50 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, 20, 0, 25, 80, 95, 70, 90, 0, 100, 45, 50, 0, 100, 55, 40, 75, 0, 50, 20, 70, 70, 80, 60] ITERATION Generation: #1 Best cost: 5290.524 | Path: [0, 1, 11, 7, 9, 15, 6, 19, 0, 22, 10, 4, 18, 16, 3, 0, 20, 13, 14, 23, 21, 0, 5, 0] Best cost: 5263.675 | Path: [0, 5, 16, 19, 3, 20, 13, 0, 4, 10, 22, 1, 11, 7, 0, 14, 6, 15, 9, 21, 23, 0, 18, 0] Best cost: 4991.323 | Path: [0, 7, 11, 1, 4, 10, 22, 19, 0, 20, 13, 9, 15, 6, 0, 3, 14, 23, 21, 5, 16, 0, 18, 0] Best cost: 4972.813 | Path: [0, 11, 7, 1, 4, 10, 22, 3, 0, 20, 13, 9, 15, 6, 19, 0, 16, 5, 21, 14, 23, 0, 18, 0] Best cost: 4921.733 | Path: [0, 3, 19, 16, 5, 21, 14, 23, 0, 4, 10, 22, 18, 1, 11, 20, 0, 13, 9, 15, 6, 7, 0] Best cost: 4880.723 | Path: [0, 6, 15, 9, 13, 20, 19, 0, 4, 10, 22, 16, 5, 3, 0, 11, 7, 1, 18, 21, 14, 23, 0] Best cost: 4829.836 | Path: [0, 20, 13, 9, 15, 6, 19, 0, 3, 14, 23, 21, 16, 5, 1, 0, 4, 22, 10, 18, 11, 7, 0] Best cost: 4748.245 | Path: [0, 4, 10, 22, 16, 5, 3, 0, 20, 13, 9, 15, 6, 19, 0, 21, 14, 23, 7, 11, 1, 18, 0] Best cost: 4730.636 | Path: [0, 20, 13, 9, 15, 6, 19, 0, 22, 10, 4, 16, 5, 3, 0, 18, 1, 7, 11, 14, 23, 21, 0] Best cost: 4717.807 | Path: [0, 23, 14, 6, 15, 9, 20, 0, 4, 10, 22, 5, 16, 3, 0, 19, 21, 13, 7, 11, 1, 18, 0] Generation: #2 Best cost: 4709.637 | Path: [0, 4, 10, 22, 16, 5, 3, 0, 20, 13, 9, 15, 6, 19, 0, 11, 7, 1, 18, 14, 23, 21, 0] Best cost: 4698.426 | Path: [0, 16, 5, 3, 19, 21, 14, 23, 0, 22, 10, 4, 18, 1, 11, 20, 0, 7, 13, 9, 15, 6, 0] Generation: #3 Best cost: 4544.771 | Path: [0, 9, 15, 6, 14, 23, 21, 0, 4, 10, 22, 16, 5, 3, 0, 19, 20, 13, 11, 7, 1, 18, 0] OPTIMIZING each tour... Current: [[0, 9, 15, 6, 14, 23, 21, 0], [0, 4, 10, 22, 16, 5, 3, 0], [0, 19, 20, 13, 11, 7, 1, 18, 0]] [2] Cost: 1173.726 to 1153.389 | Optimized: [0, 3, 16, 5, 22, 10, 4, 0] ACO RESULTS [1/395 vol./1513.827 km] Kassel-Wilhelmshöhe -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Kassel-Wilhelmshöhe [2/400 vol./1153.389 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Köln Hbf -> Aachen Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hannover Hbf --> Kassel-Wilhelmshöhe [3/400 vol./1857.218 km] Kassel-Wilhelmshöhe -> Mainz Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf -> Berlin Hbf -> Kiel Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 4524.434 km.