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 (60 vol.)
- Frankfurt Hbf (35 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (95 vol.)
- Stuttgart Hbf (25 vol.)
- Dresden Hbf (60 vol.)
- Bremen Hbf (70 vol.)
- Leipzig Hbf (70 vol.)
- Dortmund Hbf (25 vol.)
- Köln Hbf (20 vol.)
- Mannheim Hbf (65 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (30 vol.)
- Würzburg Hbf (100 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1312.887 km
LOAD: 295 vol.
- Dortmund Hbf | 25 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 20 vol.
- Aachen Hbf | 95 vol.
- Hannover Hbf | 95 vol.
Tour 2
COST: 1373.799 km
LOAD: 295 vol.
- Mainz Hbf | 30 vol.
- Frankfurt Hbf | 35 vol.
- Würzburg Hbf | 100 vol.
- Leipzig Hbf | 70 vol.
- Dresden Hbf | 60 vol.
Tour 3
COST: 2110.625 km
LOAD: 300 vol.
- Stuttgart Hbf | 25 vol.
- Freiburg Hbf | 60 vol.
- Mannheim Hbf | 65 vol.
- Bremen Hbf | 70 vol.
- Kiel Hbf | 80 vol.
LOAD: 295 vol.
- Dortmund Hbf | 25 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 20 vol.
- Aachen Hbf | 95 vol.
- Hannover Hbf | 95 vol.
LOAD: 295 vol.
- Mainz Hbf | 30 vol.
- Frankfurt Hbf | 35 vol.
- Würzburg Hbf | 100 vol.
- Leipzig Hbf | 70 vol.
- Dresden Hbf | 60 vol.
LOAD: 300 vol.
- Stuttgart Hbf | 25 vol.
- Freiburg Hbf | 60 vol.
- Mannheim Hbf | 65 vol.
- Bremen Hbf | 70 vol.
- Kiel 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: 890 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 60, 35, 95, 95, 25, 60, 0, 0, 70, 70, 25, 0, 0, 0, 20, 65, 80, 30, 100, 0, 0, 60] ITERATION Generation: #1 Best cost: 5983.289 | Path: [1, 2, 16, 5, 12, 3, 19, 6, 1, 11, 7, 20, 17, 1, 4, 10, 18, 1, 23, 1] Best cost: 5127.280 | Path: [1, 3, 19, 17, 6, 20, 16, 12, 1, 7, 11, 4, 10, 1, 18, 2, 5, 23, 1] Best cost: 4951.787 | Path: [1, 12, 16, 2, 5, 17, 19, 1, 7, 11, 4, 10, 1, 18, 3, 20, 6, 23, 1] Best cost: 4928.759 | Path: [1, 2, 16, 5, 12, 4, 1, 7, 11, 20, 19, 3, 1, 18, 10, 17, 6, 23, 1] Best cost: 4916.041 | Path: [1, 12, 2, 16, 5, 4, 1, 7, 11, 20, 3, 19, 1, 18, 10, 17, 6, 23, 1] Generation: #2 Best cost: 4909.413 | Path: [1, 23, 6, 17, 3, 19, 16, 2, 1, 7, 11, 4, 10, 1, 18, 12, 5, 20, 1] Best cost: 4898.657 | Path: [1, 3, 19, 17, 23, 6, 16, 2, 1, 7, 11, 4, 10, 1, 18, 12, 5, 20, 1] Generation: #4 Best cost: 4838.623 | Path: [1, 5, 16, 2, 12, 4, 1, 11, 7, 20, 3, 19, 1, 18, 10, 17, 23, 6, 1] Best cost: 4832.723 | Path: [1, 7, 11, 4, 10, 1, 12, 2, 16, 5, 17, 19, 1, 18, 20, 6, 23, 3, 1] Generation: #5 Best cost: 4830.138 | Path: [1, 16, 2, 5, 12, 4, 1, 7, 11, 20, 3, 19, 1, 18, 10, 17, 23, 6, 1] OPTIMIZING each tour... Current: [[1, 16, 2, 5, 12, 4, 1], [1, 7, 11, 20, 3, 19, 1], [1, 18, 10, 17, 23, 6, 1]] [1] Cost: 1342.500 to 1312.887 | Optimized: [1, 12, 2, 16, 5, 4, 1] [2] Cost: 1376.236 to 1373.799 | Optimized: [1, 19, 3, 20, 11, 7, 1] [3] Cost: 2111.402 to 2110.625 | Optimized: [1, 6, 23, 17, 10, 18, 1] ACO RESULTS [1/295 vol./1312.887 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Hannover Hbf --> Berlin Hbf [2/295 vol./1373.799 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/300 vol./2110.625 km] Berlin Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Mannheim Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4797.311 km.