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: 22 customers
- Kassel-Wilhelmshöhe (30 vol.)
- Düsseldorf Hbf (40 vol.)
- Frankfurt Hbf (70 vol.)
- Hannover Hbf (35 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (75 vol.)
- Bremen Hbf (30 vol.)
- Leipzig Hbf (40 vol.)
- Dortmund Hbf (100 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (30 vol.)
- Köln Hbf (75 vol.)
- Mannheim Hbf (40 vol.)
- Kiel Hbf (20 vol.)
- Mainz Hbf (90 vol.)
- Würzburg Hbf (45 vol.)
- Saarbrücken Hbf (95 vol.)
- Osnabrück Hbf (55 vol.)
- Freiburg Hbf (100 vol.)
Tour 1
COST: 1264.264 km
LOAD: 275 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 40 vol.
- Hannover Hbf | 35 vol.
- Bremen Hbf | 30 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 20 vol.
Tour 2
COST: 1341.989 km
LOAD: 300 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 30 vol.
- Düsseldorf Hbf | 40 vol.
- Dortmund Hbf | 100 vol.
- Osnabrück Hbf | 55 vol.
Tour 3
COST: 1456.4 km
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 30 vol.
- Frankfurt Hbf | 70 vol.
- Mainz Hbf | 90 vol.
- Mannheim Hbf | 40 vol.
- Karlsruhe Hbf | 65 vol.
Tour 4
COST: 1849.647 km
LOAD: 275 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 50 vol.
- Freiburg Hbf | 100 vol.
- Saarbrücken Hbf | 95 vol.
Tour 5
COST: 1024.947 km
LOAD: 145 vol.
- Würzburg Hbf | 45 vol.
- Nürnberg Hbf | 100 vol.
LOAD: 275 vol.
- Dresden Hbf | 75 vol.
- Leipzig Hbf | 40 vol.
- Hannover Hbf | 35 vol.
- Bremen Hbf | 30 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 20 vol.
LOAD: 300 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 30 vol.
- Düsseldorf Hbf | 40 vol.
- Dortmund Hbf | 100 vol.
- Osnabrück Hbf | 55 vol.
LOAD: 295 vol.
- Kassel-Wilhelmshöhe | 30 vol.
- Frankfurt Hbf | 70 vol.
- Mainz Hbf | 90 vol.
- Mannheim Hbf | 40 vol.
- Karlsruhe Hbf | 65 vol.
LOAD: 275 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 50 vol.
- Freiburg Hbf | 100 vol.
- Saarbrücken Hbf | 95 vol.
LOAD: 145 vol.
- Würzburg Hbf | 45 vol.
- Nürnberg Hbf | 100 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: 1290 vol. | Vehicle capacity: 300 vol. Loads: [30, 0, 40, 70, 35, 30, 50, 75, 75, 0, 30, 40, 100, 100, 65, 30, 75, 40, 20, 90, 45, 95, 55, 100] ITERATION Generation: #1 Best cost: 8103.826 | Path: [1, 0, 12, 2, 16, 5, 18, 1, 7, 11, 4, 10, 22, 20, 1, 8, 19, 3, 17, 1, 13, 15, 6, 14, 1, 23, 21, 1] Best cost: 7233.418 | Path: [1, 2, 16, 5, 12, 22, 1, 7, 11, 4, 10, 8, 18, 1, 0, 3, 19, 17, 14, 1, 13, 20, 6, 15, 1, 21, 23, 1] Best cost: 7225.566 | Path: [1, 5, 16, 2, 12, 22, 1, 7, 11, 4, 10, 8, 18, 1, 0, 3, 19, 17, 14, 1, 13, 20, 6, 15, 1, 21, 23, 1] Best cost: 7222.993 | Path: [1, 12, 2, 16, 5, 22, 1, 7, 11, 4, 10, 8, 18, 1, 0, 3, 19, 17, 14, 1, 13, 20, 6, 15, 1, 21, 23, 1] Generation: #3 Best cost: 7050.078 | Path: [1, 3, 19, 17, 14, 15, 1, 7, 11, 4, 10, 8, 18, 1, 22, 12, 2, 16, 5, 1, 20, 6, 23, 21, 1, 0, 13, 1] Generation: #6 Best cost: 7045.303 | Path: [1, 7, 11, 4, 10, 8, 18, 1, 15, 6, 14, 17, 3, 20, 1, 12, 2, 16, 5, 22, 1, 19, 21, 23, 1, 13, 0, 1] Generation: #10 Best cost: 6997.519 | Path: [1, 7, 11, 4, 10, 8, 18, 1, 16, 2, 5, 12, 22, 1, 0, 3, 19, 14, 17, 1, 15, 6, 23, 21, 1, 13, 20, 1] OPTIMIZING each tour... Current: [[1, 7, 11, 4, 10, 8, 18, 1], [1, 16, 2, 5, 12, 22, 1], [1, 0, 3, 19, 14, 17, 1], [1, 15, 6, 23, 21, 1], [1, 13, 20, 1]] [2] Cost: 1388.622 to 1341.989 | Optimized: [1, 16, 5, 2, 12, 22, 1] [3] Cost: 1466.054 to 1456.400 | Optimized: [1, 0, 3, 19, 17, 14, 1] [5] Cost: 1028.932 to 1024.947 | Optimized: [1, 20, 13, 1] ACO RESULTS [1/275 vol./1264.264 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [2/300 vol./1341.989 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Berlin Hbf [3/295 vol./1456.400 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf --> Berlin Hbf [4/275 vol./1849.647 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [5/145 vol./1024.947 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6937.247 km.