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: 14 customers
- Düsseldorf Hbf (25 vol.)
- Frankfurt Hbf (25 vol.)
- Aachen Hbf (95 vol.)
- Stuttgart Hbf (50 vol.)
- Dresden Hbf (35 vol.)
- München Hbf (90 vol.)
- Leipzig Hbf (45 vol.)
- Karlsruhe Hbf (25 vol.)
- Ulm Hbf (95 vol.)
- Mannheim Hbf (45 vol.)
- Kiel Hbf (80 vol.)
- Würzburg Hbf (95 vol.)
- Saarbrücken Hbf (40 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1557.026 km
LOAD: 295 vol.
- Mannheim Hbf | 45 vol.
- Karlsruhe Hbf | 25 vol.
- Stuttgart Hbf | 50 vol.
- Würzburg Hbf | 95 vol.
- Leipzig Hbf | 45 vol.
- Dresden Hbf | 35 vol.
Tour 2
COST: 1913.44 km
LOAD: 265 vol.
- Kiel Hbf | 80 vol.
- Düsseldorf Hbf | 25 vol.
- Aachen Hbf | 95 vol.
- Saarbrücken Hbf | 40 vol.
- Frankfurt Hbf | 25 vol.
Tour 3
COST: 1811.72 km
LOAD: 275 vol.
- München Hbf | 90 vol.
- Ulm Hbf | 95 vol.
- Freiburg Hbf | 90 vol.
LOAD: 295 vol.
- Mannheim Hbf | 45 vol.
- Karlsruhe Hbf | 25 vol.
- Stuttgart Hbf | 50 vol.
- Würzburg Hbf | 95 vol.
- Leipzig Hbf | 45 vol.
- Dresden Hbf | 35 vol.
LOAD: 265 vol.
- Kiel Hbf | 80 vol.
- Düsseldorf Hbf | 25 vol.
- Aachen Hbf | 95 vol.
- Saarbrücken Hbf | 40 vol.
- Frankfurt Hbf | 25 vol.
LOAD: 275 vol.
- München Hbf | 90 vol.
- Ulm Hbf | 95 vol.
- Freiburg 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: 835 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 25, 25, 0, 95, 50, 35, 0, 90, 0, 45, 0, 0, 25, 95, 0, 45, 80, 0, 95, 40, 0, 90] ITERATION Generation: #1 Best cost: 6020.150 | Path: [1, 2, 5, 3, 17, 14, 6, 7, 1, 11, 20, 15, 21, 1, 18, 9, 23, 1] Best cost: 5811.871 | Path: [1, 6, 14, 17, 3, 20, 11, 1, 7, 15, 9, 21, 2, 1, 18, 5, 23, 1] Best cost: 5652.432 | Path: [1, 7, 11, 20, 3, 17, 14, 2, 1, 18, 5, 21, 6, 1, 9, 15, 23, 1] Best cost: 5615.245 | Path: [1, 9, 15, 6, 14, 3, 1, 11, 7, 20, 17, 21, 2, 1, 18, 5, 23, 1] Best cost: 5491.329 | Path: [1, 11, 7, 20, 6, 14, 17, 1, 18, 2, 5, 21, 3, 1, 15, 9, 23, 1] Best cost: 5482.137 | Path: [1, 18, 17, 14, 6, 15, 1, 7, 11, 9, 20, 3, 1, 2, 5, 21, 23, 1] Best cost: 5455.467 | Path: [1, 7, 11, 20, 6, 14, 17, 1, 18, 2, 5, 21, 3, 1, 15, 9, 23, 1] Best cost: 5444.574 | Path: [1, 11, 7, 9, 15, 14, 1, 18, 3, 17, 6, 20, 1, 2, 5, 21, 23, 1] Best cost: 5416.126 | Path: [1, 2, 5, 21, 14, 17, 3, 11, 1, 7, 20, 6, 15, 1, 18, 23, 9, 1] Best cost: 5360.774 | Path: [1, 7, 11, 9, 15, 14, 1, 18, 2, 5, 3, 17, 1, 20, 6, 23, 21, 1] Best cost: 5355.021 | Path: [1, 18, 2, 5, 21, 17, 1, 7, 11, 20, 3, 14, 6, 1, 9, 15, 23, 1] Best cost: 5321.263 | Path: [1, 11, 7, 20, 6, 14, 17, 1, 18, 2, 5, 21, 3, 1, 9, 15, 23, 1] Generation: #3 Best cost: 5285.401 | Path: [1, 7, 11, 20, 6, 14, 17, 1, 18, 2, 5, 21, 3, 1, 9, 15, 23, 1] OPTIMIZING each tour... Current: [[1, 7, 11, 20, 6, 14, 17, 1], [1, 18, 2, 5, 21, 3, 1], [1, 9, 15, 23, 1]] [1] Cost: 1560.241 to 1557.026 | Optimized: [1, 17, 14, 6, 20, 11, 7, 1] ACO RESULTS [1/295 vol./1557.026 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [2/265 vol./1913.440 km] Berlin Hbf -> Kiel Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Frankfurt Hbf --> Berlin Hbf [3/275 vol./1811.720 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 5282.186 km.