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: 20 customers
- Düsseldorf Hbf (85 vol.)
- Frankfurt Hbf (100 vol.)
- Hannover Hbf (75 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (55 vol.)
- Hamburg Hbf (50 vol.)
- München Hbf (85 vol.)
- Bremen Hbf (70 vol.)
- Leipzig Hbf (20 vol.)
- Dortmund Hbf (100 vol.)
- Nürnberg Hbf (50 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (50 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (80 vol.)
- Osnabrück Hbf (45 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1493.593 km
LOAD: 285 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 50 vol.
- Nürnberg Hbf | 50 vol.
- Leipzig Hbf | 20 vol.
Tour 2
COST: 972.057 km
LOAD: 295 vol.
- Hannover Hbf | 75 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 100 vol.
Tour 3
COST: 1456.14 km
LOAD: 285 vol.
- Köln Hbf | 50 vol.
- Mainz Hbf | 80 vol.
- Frankfurt Hbf | 100 vol.
- Dresden Hbf | 55 vol.
Tour 4
COST: 1322.541 km
LOAD: 270 vol.
- Dortmund Hbf | 100 vol.
- Düsseldorf Hbf | 85 vol.
- Aachen Hbf | 40 vol.
- Osnabrück Hbf | 45 vol.
Tour 5
COST: 1623.452 km
LOAD: 250 vol.
- Mannheim Hbf | 90 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 80 vol.
LOAD: 285 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 50 vol.
- Nürnberg Hbf | 50 vol.
- Leipzig Hbf | 20 vol.
LOAD: 295 vol.
- Hannover Hbf | 75 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 50 vol.
- Kiel Hbf | 100 vol.
LOAD: 285 vol.
- Köln Hbf | 50 vol.
- Mainz Hbf | 80 vol.
- Frankfurt Hbf | 100 vol.
- Dresden Hbf | 55 vol.
LOAD: 270 vol.
- Dortmund Hbf | 100 vol.
- Düsseldorf Hbf | 85 vol.
- Aachen Hbf | 40 vol.
- Osnabrück Hbf | 45 vol.
LOAD: 250 vol.
- Mannheim Hbf | 90 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 80 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: 1385 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 85, 100, 75, 40, 50, 55, 50, 85, 70, 20, 100, 50, 80, 80, 50, 90, 100, 80, 0, 0, 45, 80] ITERATION Generation: #1 Best cost: 8340.299 | Path: [1, 2, 16, 5, 12, 11, 1, 7, 13, 17, 14, 1, 4, 10, 22, 8, 6, 1, 18, 3, 19, 1, 9, 15, 23, 1] Best cost: 7686.680 | Path: [1, 3, 19, 17, 11, 1, 7, 13, 9, 15, 1, 8, 10, 4, 22, 16, 1, 18, 2, 12, 1, 5, 14, 6, 23, 1] Best cost: 7550.249 | Path: [1, 4, 10, 22, 12, 1, 11, 7, 13, 9, 15, 1, 8, 18, 16, 2, 1, 3, 19, 17, 1, 5, 14, 6, 23, 1] Best cost: 7261.120 | Path: [1, 5, 2, 16, 12, 11, 1, 7, 13, 9, 15, 1, 4, 10, 8, 18, 1, 22, 3, 19, 6, 1, 14, 17, 23, 1] Best cost: 7260.214 | Path: [1, 10, 22, 12, 2, 1, 11, 7, 4, 8, 18, 1, 13, 9, 15, 6, 1, 3, 19, 17, 1, 23, 14, 16, 5, 1] Best cost: 7186.616 | Path: [1, 16, 2, 12, 5, 11, 1, 7, 13, 9, 15, 1, 8, 18, 10, 22, 1, 4, 3, 19, 1, 6, 14, 17, 23, 1] Best cost: 7008.707 | Path: [1, 23, 14, 17, 6, 1, 11, 7, 13, 9, 15, 1, 8, 18, 10, 4, 1, 22, 12, 2, 16, 1, 3, 19, 5, 1] Best cost: 6998.640 | Path: [1, 4, 10, 8, 18, 1, 7, 11, 13, 9, 15, 1, 22, 12, 2, 16, 1, 19, 3, 17, 1, 6, 14, 23, 5, 1] Best cost: 6988.686 | Path: [1, 23, 14, 17, 6, 1, 11, 7, 13, 9, 15, 1, 4, 10, 8, 18, 1, 22, 12, 2, 16, 1, 3, 19, 5, 1] Best cost: 6929.124 | Path: [1, 3, 19, 17, 11, 1, 7, 13, 9, 15, 1, 4, 10, 8, 18, 1, 22, 12, 2, 16, 1, 6, 14, 23, 5, 1] Generation: #2 Best cost: 6883.378 | Path: [1, 13, 9, 15, 6, 11, 1, 4, 10, 8, 18, 1, 7, 3, 19, 16, 1, 22, 12, 2, 5, 1, 17, 14, 23, 1] OPTIMIZING each tour... Current: [[1, 13, 9, 15, 6, 11, 1], [1, 4, 10, 8, 18, 1], [1, 7, 3, 19, 16, 1], [1, 22, 12, 2, 5, 1], [1, 17, 14, 23, 1]] [1] Cost: 1502.108 to 1493.593 | Optimized: [1, 9, 15, 6, 13, 11, 1] [3] Cost: 1456.391 to 1456.140 | Optimized: [1, 16, 19, 3, 7, 1] [4] Cost: 1329.370 to 1322.541 | Optimized: [1, 12, 2, 5, 22, 1] ACO RESULTS [1/285 vol./1493.593 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [2/295 vol./ 972.057 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/285 vol./1456.140 km] Berlin Hbf -> Köln Hbf -> Mainz Hbf -> Frankfurt Hbf -> Dresden Hbf --> Berlin Hbf [4/270 vol./1322.541 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Osnabrück Hbf --> Berlin Hbf [5/250 vol./1623.452 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6867.783 km.