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 (95 vol.)
- Düsseldorf Hbf (85 vol.)
- Frankfurt Hbf (35 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (50 vol.)
- Bremen Hbf (50 vol.)
- Nürnberg Hbf (25 vol.)
- Karlsruhe Hbf (30 vol.)
- Ulm Hbf (35 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (70 vol.)
- Kiel Hbf (55 vol.)
- Mainz Hbf (65 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (85 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1445.155 km
LOAD: 295 vol.
- Frankfurt Hbf | 35 vol.
- Mainz Hbf | 65 vol.
- Mannheim Hbf | 70 vol.
- Karlsruhe Hbf | 30 vol.
- Stuttgart Hbf | 70 vol.
- Würzburg Hbf | 25 vol.
Tour 2
COST: 2172.851 km
LOAD: 295 vol.
- Dresden Hbf | 35 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 35 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 85 vol.
- Osnabrück Hbf | 20 vol.
Tour 3
COST: 1484.023 km
LOAD: 290 vol.
- Hamburg Hbf | 20 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 60 vol.
- Düsseldorf Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 95 vol.
Tour 4
COST: 959.922 km
LOAD: 150 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 50 vol.
- Kiel Hbf | 55 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 35 vol.
- Mainz Hbf | 65 vol.
- Mannheim Hbf | 70 vol.
- Karlsruhe Hbf | 30 vol.
- Stuttgart Hbf | 70 vol.
- Würzburg Hbf | 25 vol.
LOAD: 295 vol.
- Dresden Hbf | 35 vol.
- Nürnberg Hbf | 25 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 35 vol.
- Freiburg Hbf | 45 vol.
- Saarbrücken Hbf | 85 vol.
- Osnabrück Hbf | 20 vol.
LOAD: 290 vol.
- Hamburg Hbf | 20 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 60 vol.
- Düsseldorf Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 95 vol.
LOAD: 150 vol.
- Hannover Hbf | 45 vol.
- Bremen Hbf | 50 vol.
- Kiel 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: [1] Berlin Hbf | Number of cities: 24 | Total loads: 1030 vol. | Vehicle capacity: 300 vol. Loads: [95, 0, 85, 35, 45, 60, 70, 35, 20, 50, 50, 0, 0, 25, 30, 35, 30, 70, 55, 65, 25, 85, 20, 45] ITERATION Generation: #1 Best cost: 7005.903 | Path: [1, 0, 3, 19, 17, 14, 1, 7, 13, 20, 6, 15, 9, 23, 1, 8, 18, 10, 22, 4, 2, 1, 16, 5, 21, 1] Best cost: 6678.898 | Path: [1, 6, 14, 17, 3, 19, 20, 1, 7, 13, 9, 15, 23, 21, 22, 1, 8, 18, 10, 4, 0, 16, 1, 2, 5, 1] Best cost: 6506.326 | Path: [1, 16, 2, 5, 21, 14, 1, 7, 13, 20, 3, 19, 17, 23, 1, 8, 18, 10, 4, 22, 0, 1, 9, 15, 6, 1] Best cost: 6464.905 | Path: [1, 5, 2, 16, 19, 3, 20, 1, 7, 13, 9, 15, 6, 14, 23, 1, 8, 18, 10, 4, 0, 22, 1, 17, 21, 1] Best cost: 6414.117 | Path: [1, 4, 10, 8, 18, 22, 0, 1, 7, 13, 20, 3, 19, 17, 14, 1, 21, 23, 6, 15, 9, 1, 5, 2, 16, 1] Best cost: 6244.052 | Path: [1, 8, 18, 10, 22, 4, 0, 1, 7, 13, 14, 17, 19, 3, 20, 1, 9, 15, 6, 23, 21, 1, 2, 16, 5, 1] Best cost: 6216.522 | Path: [1, 0, 22, 10, 4, 8, 18, 1, 7, 13, 20, 6, 14, 17, 3, 1, 19, 21, 23, 15, 9, 1, 5, 16, 2, 1] Generation: #4 Best cost: 6177.491 | Path: [1, 6, 14, 17, 3, 19, 20, 1, 7, 13, 9, 15, 23, 21, 22, 1, 0, 2, 16, 5, 8, 1, 4, 10, 18, 1] OPTIMIZING each tour... Current: [[1, 6, 14, 17, 3, 19, 20, 1], [1, 7, 13, 9, 15, 23, 21, 22, 1], [1, 0, 2, 16, 5, 8, 1], [1, 4, 10, 18, 1]] [1] Cost: 1536.583 to 1445.155 | Optimized: [1, 3, 19, 17, 14, 6, 20, 1] [3] Cost: 1508.135 to 1484.023 | Optimized: [1, 8, 16, 5, 2, 0, 1] ACO RESULTS [1/295 vol./1445.155 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [2/295 vol./2172.851 km] Berlin Hbf -> Dresden Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Osnabrück Hbf --> Berlin Hbf [3/290 vol./1484.023 km] Berlin Hbf -> Hamburg Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/150 vol./ 959.922 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6061.951 km.