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 (100 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (25 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (70 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (30 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (85 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (90 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (30 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (65 vol.)
- Saarbrücken Hbf (65 vol.)
- Osnabrück Hbf (60 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1672.847 km
LOAD: 300 vol.
- Frankfurt Hbf | 25 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 25 vol.
- Würzburg Hbf | 65 vol.
Tour 2
COST: 1098.074 km
LOAD: 290 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 85 vol.
- Hannover Hbf | 40 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 20 vol.
Tour 3
COST: 1937.776 km
LOAD: 275 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 20 vol.
- Saarbrücken Hbf | 65 vol.
- Aachen Hbf | 70 vol.
Tour 4
COST: 1467.157 km
LOAD: 275 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 30 vol.
- Osnabrück Hbf | 60 vol.
- Kiel Hbf | 30 vol.
Tour 5
COST: 785.078 km
LOAD: 100 vol.
- Kassel-Wilhelmshöhe | 100 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 25 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 75 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 25 vol.
- Würzburg Hbf | 65 vol.
LOAD: 290 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 85 vol.
- Hannover Hbf | 40 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 20 vol.
LOAD: 275 vol.
- Nürnberg Hbf | 90 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 20 vol.
- Saarbrücken Hbf | 65 vol.
- Aachen Hbf | 70 vol.
LOAD: 275 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 30 vol.
- Osnabrück Hbf | 60 vol.
- Kiel Hbf | 30 vol.
LOAD: 100 vol.
- Kassel-Wilhelmshöhe | 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: 1240 vol. | Vehicle capacity: 300 vol. Loads: [100, 0, 95, 25, 40, 70, 0, 45, 20, 30, 100, 85, 60, 90, 55, 20, 30, 75, 30, 55, 65, 65, 60, 25] ITERATION Generation: #1 Best cost: 8217.786 | Path: [1, 0, 2, 16, 5, 1, 11, 7, 13, 20, 1, 4, 10, 8, 18, 22, 3, 15, 1, 12, 19, 17, 14, 23, 9, 1, 21, 1] Best cost: 8009.791 | Path: [1, 2, 16, 5, 12, 4, 1, 7, 11, 3, 19, 17, 1, 8, 18, 10, 22, 14, 23, 1, 0, 20, 13, 9, 1, 15, 21, 1] Best cost: 7805.926 | Path: [1, 3, 19, 17, 14, 23, 21, 1, 11, 7, 13, 20, 1, 8, 18, 10, 4, 22, 16, 15, 1, 12, 2, 5, 9, 1, 0, 1] Best cost: 7676.467 | Path: [1, 18, 8, 10, 22, 12, 16, 1, 11, 7, 13, 20, 1, 4, 0, 19, 3, 17, 1, 9, 15, 14, 21, 23, 2, 1, 5, 1] Best cost: 7608.386 | Path: [1, 4, 0, 12, 2, 1, 7, 11, 13, 20, 1, 18, 8, 10, 22, 16, 19, 1, 17, 14, 23, 21, 3, 15, 9, 1, 5, 1] Best cost: 7386.316 | Path: [1, 8, 18, 10, 4, 0, 1, 7, 11, 13, 20, 1, 22, 12, 2, 16, 19, 1, 17, 14, 3, 21, 23, 15, 9, 1, 5, 1] Best cost: 7321.075 | Path: [1, 9, 15, 14, 17, 19, 3, 16, 1, 11, 7, 13, 20, 1, 4, 10, 22, 12, 8, 1, 18, 2, 5, 21, 23, 1, 0, 1] Best cost: 7133.764 | Path: [1, 19, 3, 17, 14, 23, 21, 1, 7, 11, 4, 10, 8, 1, 18, 12, 2, 16, 5, 1, 22, 0, 20, 15, 9, 1, 13, 1] Generation: #2 Best cost: 7034.156 | Path: [1, 23, 14, 17, 19, 3, 20, 1, 7, 11, 4, 10, 8, 1, 13, 9, 15, 21, 5, 1, 18, 22, 12, 2, 16, 1, 0, 1] OPTIMIZING each tour... Current: [[1, 23, 14, 17, 19, 3, 20, 1], [1, 7, 11, 4, 10, 8, 1], [1, 13, 9, 15, 21, 5, 1], [1, 18, 22, 12, 2, 16, 1], [1, 0, 1]] [1] Cost: 1732.852 to 1672.847 | Optimized: [1, 3, 19, 17, 14, 23, 20, 1] [4] Cost: 1480.376 to 1467.157 | Optimized: [1, 12, 2, 16, 22, 18, 1] ACO RESULTS [1/300 vol./1672.847 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [2/290 vol./1098.074 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/275 vol./1937.776 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Saarbrücken Hbf -> Aachen Hbf --> Berlin Hbf [4/275 vol./1467.157 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Osnabrück Hbf -> Kiel Hbf --> Berlin Hbf [5/100 vol./ 785.078 km] Berlin Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6960.932 km.