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: 15 customers
- Düsseldorf Hbf (35 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (45 vol.)
- Leipzig Hbf (50 vol.)
- Nürnberg Hbf (20 vol.)
- Karlsruhe Hbf (90 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (70 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (45 vol.)
- Mainz Hbf (85 vol.)
- Würzburg Hbf (20 vol.)
- Saarbrücken Hbf (30 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1972.487 km
LOAD: 300 vol.
- Würzburg Hbf | 20 vol.
- Mainz Hbf | 85 vol.
- Mannheim Hbf | 100 vol.
- Saarbrücken Hbf | 30 vol.
- Freiburg Hbf | 25 vol.
- Ulm Hbf | 20 vol.
- Nürnberg Hbf | 20 vol.
Tour 2
COST: 1165.88 km
LOAD: 275 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 50 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 45 vol.
Tour 3
COST: 1762.171 km
LOAD: 240 vol.
- München Hbf | 45 vol.
- Karlsruhe Hbf | 90 vol.
- Köln Hbf | 70 vol.
- Düsseldorf Hbf | 35 vol.
LOAD: 300 vol.
- Würzburg Hbf | 20 vol.
- Mainz Hbf | 85 vol.
- Mannheim Hbf | 100 vol.
- Saarbrücken Hbf | 30 vol.
- Freiburg Hbf | 25 vol.
- Ulm Hbf | 20 vol.
- Nürnberg Hbf | 20 vol.
LOAD: 275 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 50 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 45 vol.
LOAD: 240 vol.
- München Hbf | 45 vol.
- Karlsruhe Hbf | 90 vol.
- Köln Hbf | 70 vol.
- Düsseldorf Hbf | 35 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: 815 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 35, 0, 0, 0, 0, 95, 85, 45, 0, 50, 0, 20, 90, 20, 70, 100, 45, 85, 20, 30, 0, 25] ITERATION Generation: #1 Best cost: 5818.737 | Path: [1, 2, 16, 19, 17, 1, 11, 7, 13, 20, 14, 23, 1, 8, 18, 15, 9, 21, 1] Best cost: 5599.121 | Path: [1, 7, 11, 13, 20, 19, 21, 1, 8, 18, 16, 2, 23, 15, 1, 17, 14, 9, 1] Best cost: 5548.458 | Path: [1, 9, 13, 20, 19, 17, 21, 1, 11, 7, 14, 15, 23, 1, 8, 18, 16, 2, 1] Best cost: 5156.544 | Path: [1, 14, 17, 19, 20, 1, 7, 11, 13, 9, 15, 21, 23, 1, 8, 18, 2, 16, 1] Best cost: 5057.276 | Path: [1, 14, 17, 19, 20, 1, 7, 11, 13, 9, 15, 23, 21, 1, 8, 18, 2, 16, 1] Best cost: 5055.613 | Path: [1, 14, 17, 19, 20, 1, 7, 11, 13, 9, 15, 23, 21, 1, 18, 8, 16, 2, 1] Best cost: 4969.366 | Path: [1, 13, 20, 19, 17, 21, 23, 15, 1, 7, 11, 8, 18, 1, 2, 16, 14, 9, 1] Best cost: 4957.470 | Path: [1, 13, 20, 19, 17, 21, 23, 15, 1, 7, 11, 8, 18, 1, 9, 14, 16, 2, 1] OPTIMIZING each tour... Current: [[1, 13, 20, 19, 17, 21, 23, 15, 1], [1, 7, 11, 8, 18, 1], [1, 9, 14, 16, 2, 1]] [1] Cost: 2029.419 to 1972.487 | Optimized: [1, 20, 19, 17, 21, 23, 15, 13, 1] ACO RESULTS [1/300 vol./1972.487 km] Berlin Hbf -> Würzburg Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Ulm Hbf -> Nürnberg Hbf --> Berlin Hbf [2/275 vol./1165.880 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/240 vol./1762.171 km] Berlin Hbf -> München Hbf -> Karlsruhe Hbf -> Köln Hbf -> Düsseldorf Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4900.538 km.