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 (90 vol.)
- Frankfurt Hbf (85 vol.)
- Aachen Hbf (50 vol.)
- Stuttgart Hbf (90 vol.)
- Dresden Hbf (40 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (95 vol.)
- Bremen Hbf (85 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (55 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (80 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (35 vol.)
- Osnabrück Hbf (100 vol.)
- Freiburg Hbf (65 vol.)
Tour 1
COST: 1537.673 km
LOAD: 300 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 90 vol.
- Nürnberg Hbf | 55 vol.
- Dresden Hbf | 40 vol.
Tour 2
COST: 941.643 km
LOAD: 285 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 100 vol.
Tour 3
COST: 1291.407 km
LOAD: 285 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 50 vol.
- Düsseldorf Hbf | 90 vol.
- Dortmund Hbf | 85 vol.
Tour 4
COST: 1790.817 km
LOAD: 270 vol.
- Mainz Hbf | 25 vol.
- Saarbrücken Hbf | 35 vol.
- Freiburg Hbf | 65 vol.
- Karlsruhe Hbf | 40 vol.
- Mannheim Hbf | 80 vol.
- Würzburg Hbf | 25 vol.
Tour 5
COST: 1092.475 km
LOAD: 85 vol.
- Frankfurt Hbf | 85 vol.
LOAD: 300 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 90 vol.
- Nürnberg Hbf | 55 vol.
- Dresden Hbf | 40 vol.
LOAD: 285 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 100 vol.
LOAD: 285 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 50 vol.
- Düsseldorf Hbf | 90 vol.
- Dortmund Hbf | 85 vol.
LOAD: 270 vol.
- Mainz Hbf | 25 vol.
- Saarbrücken Hbf | 35 vol.
- Freiburg Hbf | 65 vol.
- Karlsruhe Hbf | 40 vol.
- Mannheim Hbf | 80 vol.
- Würzburg Hbf | 25 vol.
LOAD: 85 vol.
- Frankfurt Hbf | 85 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, 90, 85, 0, 50, 90, 40, 100, 95, 85, 0, 85, 55, 40, 20, 60, 80, 0, 25, 25, 35, 100, 65] ITERATION Generation: #1 Best cost: 7337.907 | Path: [1, 2, 16, 5, 12, 1, 7, 20, 6, 14, 17, 19, 1, 8, 10, 22, 1, 13, 9, 15, 3, 21, 1, 23, 1] Best cost: 7022.034 | Path: [1, 3, 19, 17, 14, 23, 1, 7, 13, 20, 6, 15, 21, 1, 8, 10, 22, 1, 16, 2, 5, 12, 1, 9, 1] Best cost: 7014.848 | Path: [1, 19, 3, 17, 14, 23, 1, 7, 13, 20, 6, 15, 21, 1, 8, 10, 22, 1, 12, 2, 16, 5, 1, 9, 1] Best cost: 6907.764 | Path: [1, 6, 14, 17, 3, 1, 7, 13, 20, 19, 21, 23, 15, 1, 8, 10, 22, 1, 5, 2, 16, 12, 1, 9, 1] Best cost: 6808.805 | Path: [1, 17, 14, 6, 15, 13, 1, 7, 20, 3, 19, 21, 23, 1, 8, 10, 22, 1, 12, 2, 16, 5, 1, 9, 1] Best cost: 6762.537 | Path: [1, 2, 16, 5, 12, 1, 7, 9, 15, 6, 14, 1, 8, 10, 22, 1, 3, 19, 17, 21, 23, 1, 13, 20, 1] Generation: #6 Best cost: 6752.450 | Path: [1, 7, 9, 15, 6, 14, 1, 8, 10, 22, 1, 3, 19, 17, 21, 23, 1, 12, 2, 16, 5, 1, 13, 20, 1] Generation: #8 Best cost: 6701.036 | Path: [1, 7, 13, 9, 15, 6, 1, 8, 10, 22, 1, 12, 2, 16, 5, 1, 17, 14, 23, 21, 19, 20, 1, 3, 1] OPTIMIZING each tour... Current: [[1, 7, 13, 9, 15, 6, 1], [1, 8, 10, 22, 1], [1, 12, 2, 16, 5, 1], [1, 17, 14, 23, 21, 19, 20, 1], [1, 3, 1]] [1] Cost: 1546.120 to 1537.673 | Optimized: [1, 9, 15, 6, 13, 7, 1] [2] Cost: 947.067 to 941.643 | Optimized: [1, 22, 10, 8, 1] [3] Cost: 1308.428 to 1291.407 | Optimized: [1, 16, 5, 2, 12, 1] [4] Cost: 1806.946 to 1790.817 | Optimized: [1, 19, 21, 23, 14, 17, 20, 1] ACO RESULTS [1/300 vol./1537.673 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [2/285 vol./ 941.643 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/285 vol./1291.407 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf [4/270 vol./1790.817 km] Berlin Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Würzburg Hbf --> Berlin Hbf [5/ 85 vol./1092.475 km] Berlin Hbf -> Frankfurt Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6654.015 km.