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: 19 customers
- Düsseldorf Hbf (30 vol.)
- Frankfurt Hbf (90 vol.)
- Hannover Hbf (30 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (100 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (95 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (70 vol.)
- Leipzig Hbf (75 vol.)
- Dortmund Hbf (60 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (95 vol.)
- Mannheim Hbf (55 vol.)
- Kiel Hbf (85 vol.)
- Mainz Hbf (45 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (35 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1480.9 km
LOAD: 295 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 45 vol.
- Stuttgart Hbf | 100 vol.
- Ulm Hbf | 95 vol.
Tour 2
COST: 1561.668 km
LOAD: 300 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 75 vol.
- Frankfurt Hbf | 90 vol.
- Mainz Hbf | 45 vol.
- Düsseldorf Hbf | 30 vol.
- Osnabrück Hbf | 35 vol.
Tour 3
COST: 972.057 km
LOAD: 280 vol.
- Hannover Hbf | 30 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 85 vol.
Tour 4
COST: 2091.204 km
LOAD: 290 vol.
- München Hbf | 25 vol.
- Freiburg Hbf | 85 vol.
- Saarbrücken Hbf | 100 vol.
- Aachen Hbf | 80 vol.
Tour 5
COST: 981.267 km
LOAD: 60 vol.
- Dortmund Hbf | 60 vol.
LOAD: 295 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 45 vol.
- Stuttgart Hbf | 100 vol.
- Ulm Hbf | 95 vol.
LOAD: 300 vol.
- Dresden Hbf | 25 vol.
- Leipzig Hbf | 75 vol.
- Frankfurt Hbf | 90 vol.
- Mainz Hbf | 45 vol.
- Düsseldorf Hbf | 30 vol.
- Osnabrück Hbf | 35 vol.
LOAD: 280 vol.
- Hannover Hbf | 30 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 95 vol.
- Kiel Hbf | 85 vol.
LOAD: 290 vol.
- München Hbf | 25 vol.
- Freiburg Hbf | 85 vol.
- Saarbrücken Hbf | 100 vol.
- Aachen Hbf | 80 vol.
LOAD: 60 vol.
- Dortmund Hbf | 60 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: 1225 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 30, 90, 30, 80, 100, 25, 95, 25, 70, 75, 60, 0, 45, 95, 0, 55, 85, 45, 0, 100, 35, 85] ITERATION Generation: #1 Best cost: 8320.036 | Path: [1, 2, 12, 22, 10, 8, 1, 7, 11, 4, 18, 5, 1, 14, 17, 19, 3, 9, 1, 15, 6, 23, 1, 21, 1] Best cost: 7897.189 | Path: [1, 3, 19, 17, 14, 9, 7, 1, 11, 4, 10, 22, 12, 2, 1, 8, 18, 5, 1, 15, 6, 23, 1, 21, 1] Best cost: 7655.092 | Path: [1, 4, 10, 8, 18, 1, 7, 11, 22, 12, 2, 19, 9, 1, 3, 17, 14, 6, 1, 5, 21, 23, 1, 15, 1] Best cost: 7466.892 | Path: [1, 5, 2, 12, 22, 10, 7, 1, 11, 4, 8, 18, 1, 3, 19, 17, 14, 9, 1, 23, 21, 6, 1, 15, 1] Best cost: 7285.725 | Path: [1, 18, 8, 10, 22, 1, 11, 7, 4, 12, 2, 5, 1, 17, 14, 6, 15, 1, 9, 23, 21, 19, 1, 3, 1] Best cost: 7178.353 | Path: [1, 15, 6, 14, 17, 1, 7, 11, 4, 10, 8, 1, 18, 22, 12, 2, 5, 1, 9, 23, 21, 19, 1, 3, 1] Generation: #3 Best cost: 7175.923 | Path: [1, 17, 14, 6, 15, 1, 7, 11, 4, 10, 8, 1, 18, 22, 12, 2, 5, 1, 9, 23, 21, 19, 1, 3, 1] Generation: #5 Best cost: 7174.923 | Path: [1, 15, 6, 14, 17, 1, 11, 7, 3, 19, 2, 22, 1, 8, 18, 10, 4, 1, 9, 23, 21, 5, 1, 12, 1] OPTIMIZING each tour... Current: [[1, 15, 6, 14, 17, 1], [1, 11, 7, 3, 19, 2, 22, 1], [1, 8, 18, 10, 4, 1], [1, 9, 23, 21, 5, 1], [1, 12, 1]] [1] Cost: 1483.330 to 1480.900 | Optimized: [1, 17, 14, 6, 15, 1] [2] Cost: 1627.044 to 1561.668 | Optimized: [1, 7, 11, 3, 19, 2, 22, 1] [3] Cost: 992.078 to 972.057 | Optimized: [1, 4, 10, 8, 18, 1] ACO RESULTS [1/295 vol./1480.900 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [2/300 vol./1561.668 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Frankfurt Hbf -> Mainz Hbf -> Düsseldorf Hbf -> Osnabrück Hbf --> Berlin Hbf [3/280 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/290 vol./2091.204 km] Berlin Hbf -> München Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Aachen Hbf --> Berlin Hbf [5/ 60 vol./ 981.267 km] Berlin Hbf -> Dortmund Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7087.096 km.