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: 17 customers
- Kassel-Wilhelmshöhe (75 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (45 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (30 vol.)
- Leipzig Hbf (45 vol.)
- Dortmund Hbf (65 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (40 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (65 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (65 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1656.954 km
LOAD: 290 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 45 vol.
- Würzburg Hbf | 95 vol.
- Mannheim Hbf | 65 vol.
- Ulm Hbf | 40 vol.
Tour 2
COST: 1469.183 km
LOAD: 300 vol.
- Hamburg Hbf | 40 vol.
- Bremen Hbf | 30 vol.
- Osnabrück Hbf | 20 vol.
- Dortmund Hbf | 65 vol.
- Köln Hbf | 55 vol.
- Aachen Hbf | 45 vol.
- Hannover Hbf | 45 vol.
Tour 3
COST: 1930.722 km
LOAD: 275 vol.
- München Hbf | 80 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 65 vol.
Tour 4
COST: 785.078 km
LOAD: 75 vol.
- Kassel-Wilhelmshöhe | 75 vol.
LOAD: 290 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 45 vol.
- Würzburg Hbf | 95 vol.
- Mannheim Hbf | 65 vol.
- Ulm Hbf | 40 vol.
LOAD: 300 vol.
- Hamburg Hbf | 40 vol.
- Bremen Hbf | 30 vol.
- Osnabrück Hbf | 20 vol.
- Dortmund Hbf | 65 vol.
- Köln Hbf | 55 vol.
- Aachen Hbf | 45 vol.
- Hannover Hbf | 45 vol.
LOAD: 275 vol.
- München Hbf | 80 vol.
- Karlsruhe Hbf | 65 vol.
- Freiburg Hbf | 65 vol.
- Saarbrücken Hbf | 65 vol.
LOAD: 75 vol.
- Kassel-Wilhelmshöhe | 75 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: 940 vol. | Vehicle capacity: 300 vol. Loads: [75, 0, 0, 0, 45, 45, 0, 45, 40, 80, 30, 45, 65, 0, 65, 40, 55, 65, 0, 0, 95, 65, 20, 65] ITERATION Generation: #1 Best cost: 6791.164 | Path: [1, 0, 12, 16, 5, 22, 10, 1, 11, 7, 4, 8, 20, 1, 15, 9, 14, 17, 1, 21, 23, 1] Best cost: 6293.392 | Path: [1, 5, 16, 12, 22, 10, 8, 4, 1, 11, 7, 20, 15, 14, 1, 0, 17, 21, 23, 1, 9, 1] Best cost: 6287.937 | Path: [1, 8, 10, 4, 22, 12, 16, 5, 1, 11, 7, 20, 15, 14, 1, 0, 17, 21, 23, 1, 9, 1] Best cost: 6280.930 | Path: [1, 5, 16, 12, 22, 4, 10, 8, 1, 11, 7, 15, 9, 14, 1, 0, 17, 21, 23, 1, 20, 1] Best cost: 6278.646 | Path: [1, 16, 5, 12, 22, 10, 4, 8, 1, 7, 11, 0, 20, 15, 1, 14, 17, 21, 23, 1, 9, 1] Best cost: 6197.882 | Path: [1, 17, 14, 23, 21, 15, 1, 11, 7, 20, 0, 22, 1, 4, 8, 10, 12, 16, 5, 1, 9, 1] Best cost: 6168.975 | Path: [1, 5, 16, 12, 22, 10, 8, 4, 1, 11, 7, 20, 15, 14, 1, 9, 17, 21, 23, 1, 0, 1] Best cost: 5926.043 | Path: [1, 16, 5, 12, 22, 4, 10, 8, 1, 11, 7, 9, 15, 14, 1, 20, 17, 21, 23, 1, 0, 1] Generation: #2 Best cost: 5892.568 | Path: [1, 12, 16, 5, 21, 17, 1, 7, 11, 0, 22, 10, 4, 8, 1, 9, 15, 14, 23, 1, 20, 1] Generation: #6 Best cost: 5877.799 | Path: [1, 11, 7, 20, 17, 15, 1, 8, 10, 22, 12, 16, 5, 4, 1, 9, 14, 23, 21, 1, 0, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 20, 17, 15, 1], [1, 8, 10, 22, 12, 16, 5, 4, 1], [1, 9, 14, 23, 21, 1], [1, 0, 1]] [1] Cost: 1692.816 to 1656.954 | Optimized: [1, 7, 11, 20, 17, 15, 1] ACO RESULTS [1/290 vol./1656.954 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Würzburg Hbf -> Mannheim Hbf -> Ulm Hbf --> Berlin Hbf [2/300 vol./1469.183 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Osnabrück Hbf -> Dortmund Hbf -> Köln Hbf -> Aachen Hbf -> Hannover Hbf --> Berlin Hbf [3/275 vol./1930.722 km] Berlin Hbf -> München Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [4/ 75 vol./ 785.078 km] Berlin Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5841.937 km.