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 (65 vol.)
- Frankfurt Hbf (75 vol.)
- Aachen Hbf (85 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (75 vol.)
- München Hbf (90 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (55 vol.)
- Nürnberg Hbf (40 vol.)
- Karlsruhe Hbf (80 vol.)
- Ulm Hbf (60 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (30 vol.)
- Mainz Hbf (80 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (60 vol.)
Tour 1
COST: 1658.843 km
LOAD: 295 vol.
- Saarbrücken Hbf | 60 vol.
- Karlsruhe Hbf | 80 vol.
- Stuttgart Hbf | 95 vol.
- Ulm Hbf | 60 vol.
Tour 2
COST: 1245.897 km
LOAD: 270 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 35 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 30 vol.
Tour 3
COST: 1329.758 km
LOAD: 295 vol.
- Frankfurt Hbf | 75 vol.
- Mainz Hbf | 80 vol.
- Mannheim Hbf | 90 vol.
- Würzburg Hbf | 50 vol.
Tour 4
COST: 1291.407 km
LOAD: 275 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 85 vol.
- Düsseldorf Hbf | 65 vol.
- Dortmund Hbf | 55 vol.
Tour 5
COST: 1189.939 km
LOAD: 130 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 90 vol.
LOAD: 295 vol.
- Saarbrücken Hbf | 60 vol.
- Karlsruhe Hbf | 80 vol.
- Stuttgart Hbf | 95 vol.
- Ulm Hbf | 60 vol.
LOAD: 270 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 35 vol.
- Bremen Hbf | 35 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 30 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 75 vol.
- Mainz Hbf | 80 vol.
- Mannheim Hbf | 90 vol.
- Würzburg Hbf | 50 vol.
LOAD: 275 vol.
- Köln Hbf | 70 vol.
- Aachen Hbf | 85 vol.
- Düsseldorf Hbf | 65 vol.
- Dortmund Hbf | 55 vol.
LOAD: 130 vol.
- Nürnberg Hbf | 40 vol.
- München Hbf | 90 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: 1265 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 65, 75, 0, 85, 95, 95, 75, 90, 35, 35, 55, 40, 80, 60, 70, 90, 30, 80, 50, 60, 0, 0] ITERATION Generation: #1 Best cost: 7545.128 | Path: [1, 2, 16, 5, 12, 1, 11, 7, 13, 20, 3, 1, 8, 18, 10, 19, 14, 1, 6, 15, 9, 1, 17, 21, 1] Best cost: 6906.408 | Path: [1, 3, 19, 17, 20, 1, 7, 11, 10, 8, 18, 1, 13, 9, 15, 6, 1, 2, 16, 5, 12, 1, 14, 21, 1] Best cost: 6894.204 | Path: [1, 14, 17, 3, 20, 1, 7, 11, 10, 8, 18, 1, 13, 9, 15, 6, 1, 12, 2, 16, 5, 1, 21, 19, 1] Best cost: 6783.654 | Path: [1, 15, 6, 14, 21, 1, 7, 11, 10, 8, 18, 1, 20, 3, 19, 17, 1, 16, 2, 5, 12, 1, 13, 9, 1] OPTIMIZING each tour... Current: [[1, 15, 6, 14, 21, 1], [1, 7, 11, 10, 8, 18, 1], [1, 20, 3, 19, 17, 1], [1, 16, 2, 5, 12, 1], [1, 13, 9, 1]] [1] Cost: 1662.145 to 1658.843 | Optimized: [1, 21, 14, 6, 15, 1] [3] Cost: 1347.633 to 1329.758 | Optimized: [1, 3, 19, 17, 20, 1] [4] Cost: 1338.040 to 1291.407 | Optimized: [1, 16, 5, 2, 12, 1] ACO RESULTS [1/295 vol./1658.843 km] Berlin Hbf -> Saarbrücken Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [2/270 vol./1245.897 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/295 vol./1329.758 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Würzburg Hbf --> Berlin Hbf [4/275 vol./1291.407 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf [5/130 vol./1189.939 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6715.844 km.