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: 300 vol.
ACTIVE: 21 customers
- Kassel-Wilhelmshöhe (25 vol.)
- Düsseldorf Hbf (60 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (85 vol.)
- Bremen Hbf (65 vol.)
- Leipzig Hbf (55 vol.)
- Dortmund Hbf (25 vol.)
- Nürnberg Hbf (95 vol.)
- Karlsruhe Hbf (25 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (40 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (100 vol.)
Tour 1
COST: 1810.697 km
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 25 vol.
- Frankfurt Hbf | 40 vol.
- Karlsruhe Hbf | 25 vol.
- Saarbrücken Hbf | 40 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 60 vol.
- Dortmund Hbf | 25 vol.
Tour 2
COST: 1153.599 km
LOAD: 300 vol.
- Leipzig Hbf | 55 vol.
- Nürnberg Hbf | 95 vol.
- Würzburg Hbf | 80 vol.
- Dresden Hbf | 70 vol.
Tour 3
COST: 1113.837 km
LOAD: 260 vol.
- Hannover Hbf | 40 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 20 vol.
Tour 4
COST: 1654.796 km
LOAD: 290 vol.
- Mainz Hbf | 100 vol.
- Mannheim Hbf | 90 vol.
- Freiburg Hbf | 100 vol.
Tour 5
COST: 1257.802 km
LOAD: 95 vol.
- Stuttgart Hbf | 95 vol.
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 25 vol.
- Frankfurt Hbf | 40 vol.
- Karlsruhe Hbf | 25 vol.
- Saarbrücken Hbf | 40 vol.
- Aachen Hbf | 40 vol.
- Köln Hbf | 30 vol.
- Düsseldorf Hbf | 60 vol.
- Dortmund Hbf | 25 vol.
LOAD: 300 vol.
- Leipzig Hbf | 55 vol.
- Nürnberg Hbf | 95 vol.
- Würzburg Hbf | 80 vol.
- Dresden Hbf | 70 vol.
LOAD: 260 vol.
- Hannover Hbf | 40 vol.
- Osnabrück Hbf | 50 vol.
- Bremen Hbf | 65 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 20 vol.
LOAD: 290 vol.
- Mainz Hbf | 100 vol.
- Mannheim Hbf | 90 vol.
- Freiburg Hbf | 100 vol.
LOAD: 95 vol.
- Stuttgart Hbf | 95 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: [1] Berlin Hbf | Number of cities: 24 | Total loads: 1230 vol. | Vehicle capacity: 300 vol. Loads: [25, 0, 60, 40, 40, 40, 95, 70, 85, 0, 65, 55, 25, 95, 25, 0, 30, 90, 20, 100, 80, 40, 50, 100] ITERATION Generation: #1 Best cost: 8072.827 | Path: [1, 0, 20, 13, 6, 1, 11, 7, 4, 10, 22, 18, 1, 8, 12, 2, 16, 5, 3, 1, 17, 14, 19, 21, 1, 23, 1] Best cost: 7655.005 | Path: [1, 3, 19, 17, 14, 21, 1, 11, 7, 13, 20, 1, 8, 18, 10, 22, 4, 12, 1, 0, 2, 16, 5, 23, 1, 6, 1] Best cost: 7571.197 | Path: [1, 4, 10, 8, 18, 22, 12, 1, 11, 7, 13, 20, 1, 2, 16, 5, 21, 17, 14, 1, 0, 19, 3, 23, 1, 6, 1] Best cost: 7369.061 | Path: [1, 8, 18, 4, 10, 22, 12, 1, 7, 11, 13, 20, 1, 0, 19, 3, 17, 14, 1, 2, 16, 5, 21, 23, 1, 6, 1] Best cost: 7319.817 | Path: [1, 0, 22, 10, 4, 8, 18, 1, 11, 7, 13, 20, 1, 12, 2, 16, 5, 3, 19, 1, 14, 17, 21, 23, 1, 6, 1] Best cost: 7259.997 | Path: [1, 12, 2, 16, 5, 21, 23, 1, 7, 11, 13, 20, 1, 4, 8, 18, 10, 22, 0, 1, 19, 3, 17, 14, 1, 6, 1] Generation: #2 Best cost: 7242.387 | Path: [1, 8, 18, 10, 4, 22, 12, 1, 11, 7, 13, 20, 1, 0, 3, 19, 17, 14, 1, 6, 23, 21, 5, 1, 2, 16, 1] Best cost: 7087.040 | Path: [1, 17, 14, 6, 20, 1, 7, 11, 4, 10, 22, 18, 1, 8, 0, 12, 2, 16, 5, 1, 3, 19, 21, 23, 1, 13, 1] Generation: #5 Best cost: 7086.200 | Path: [1, 12, 2, 16, 5, 21, 14, 3, 0, 1, 11, 7, 13, 20, 1, 8, 18, 10, 22, 4, 1, 23, 17, 19, 1, 6, 1] OPTIMIZING each tour... Current: [[1, 12, 2, 16, 5, 21, 14, 3, 0, 1], [1, 11, 7, 13, 20, 1], [1, 8, 18, 10, 22, 4, 1], [1, 23, 17, 19, 1], [1, 6, 1]] [1] Cost: 1814.567 to 1810.697 | Optimized: [1, 0, 3, 14, 21, 5, 16, 2, 12, 1] [2] Cost: 1216.319 to 1153.599 | Optimized: [1, 11, 13, 20, 7, 1] [3] Cost: 1136.947 to 1113.837 | Optimized: [1, 4, 22, 10, 8, 18, 1] [4] Cost: 1660.565 to 1654.796 | Optimized: [1, 19, 17, 23, 1] ACO RESULTS [1/285 vol./1810.697 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Karlsruhe Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf [2/300 vol./1153.599 km] Berlin Hbf -> Leipzig Hbf -> Nürnberg Hbf -> Würzburg Hbf -> Dresden Hbf --> Berlin Hbf [3/260 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/290 vol./1654.796 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Freiburg Hbf --> Berlin Hbf [5/ 95 vol./1257.802 km] Berlin Hbf -> Stuttgart Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6990.731 km.