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: 17 customers
- Kassel-Wilhelmshöhe (65 vol.)
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (20 vol.)
- Hannover Hbf (55 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (30 vol.)
- Hamburg Hbf (75 vol.)
- München Hbf (95 vol.)
- Dortmund Hbf (85 vol.)
- Karlsruhe Hbf (45 vol.)
- Ulm Hbf (95 vol.)
- Köln Hbf (65 vol.)
- Mannheim Hbf (95 vol.)
- Mainz Hbf (50 vol.)
- Würzburg Hbf (95 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1525.828 km
LOAD: 300 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 35 vol.
- Köln Hbf | 65 vol.
- Aachen Hbf | 30 vol.
- Frankfurt Hbf | 20 vol.
- Kassel-Wilhelmshöhe | 65 vol.
Tour 2
COST: 1503.5 km
LOAD: 300 vol.
- Dresden Hbf | 30 vol.
- Würzburg Hbf | 95 vol.
- Stuttgart Hbf | 30 vol.
- Mannheim Hbf | 95 vol.
- Mainz Hbf | 50 vol.
Tour 3
COST: 1816.316 km
LOAD: 285 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 95 vol.
- Freiburg Hbf | 50 vol.
- Karlsruhe Hbf | 45 vol.
Tour 4
COST: 715.744 km
LOAD: 130 vol.
- Hannover Hbf | 55 vol.
- Hamburg Hbf | 75 vol.
LOAD: 300 vol.
- Dortmund Hbf | 85 vol.
- Düsseldorf Hbf | 35 vol.
- Köln Hbf | 65 vol.
- Aachen Hbf | 30 vol.
- Frankfurt Hbf | 20 vol.
- Kassel-Wilhelmshöhe | 65 vol.
LOAD: 300 vol.
- Dresden Hbf | 30 vol.
- Würzburg Hbf | 95 vol.
- Stuttgart Hbf | 30 vol.
- Mannheim Hbf | 95 vol.
- Mainz Hbf | 50 vol.
LOAD: 285 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 95 vol.
- Freiburg Hbf | 50 vol.
- Karlsruhe Hbf | 45 vol.
LOAD: 130 vol.
- Hannover Hbf | 55 vol.
- Hamburg Hbf | 75 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: 1015 vol. | Vehicle capacity: 300 vol. Loads: [65, 0, 35, 20, 55, 30, 30, 30, 75, 95, 0, 0, 85, 0, 45, 95, 65, 95, 0, 50, 95, 0, 0, 50] ITERATION Generation: #1 Best cost: 6724.980 | Path: [1, 0, 12, 2, 16, 5, 3, 1, 7, 20, 19, 17, 6, 1, 8, 4, 15, 14, 1, 9, 23, 1] Best cost: 6682.441 | Path: [1, 2, 16, 5, 12, 19, 3, 1, 7, 0, 20, 14, 6, 1, 4, 8, 17, 23, 1, 15, 9, 1] Best cost: 6520.705 | Path: [1, 3, 19, 17, 14, 6, 23, 1, 7, 0, 4, 8, 16, 1, 20, 9, 15, 1, 12, 2, 5, 1] Best cost: 6298.755 | Path: [1, 4, 8, 0, 12, 3, 1, 7, 9, 15, 6, 14, 1, 19, 17, 23, 20, 1, 2, 16, 5, 1] Best cost: 6204.101 | Path: [1, 12, 2, 16, 5, 19, 3, 1, 7, 17, 14, 6, 15, 1, 8, 4, 0, 20, 1, 9, 23, 1] Best cost: 6116.339 | Path: [1, 14, 17, 19, 3, 16, 1, 7, 9, 15, 6, 23, 1, 8, 4, 0, 20, 1, 12, 2, 5, 1] Best cost: 6113.542 | Path: [1, 19, 3, 17, 14, 6, 23, 1, 7, 20, 0, 12, 1, 8, 4, 16, 2, 5, 1, 9, 15, 1] Best cost: 6036.213 | Path: [1, 5, 2, 16, 3, 19, 17, 1, 7, 20, 6, 14, 23, 1, 8, 4, 0, 12, 1, 9, 15, 1] Generation: #4 Best cost: 5650.463 | Path: [1, 0, 12, 2, 16, 5, 3, 1, 7, 20, 19, 17, 6, 1, 9, 15, 14, 23, 1, 8, 4, 1] OPTIMIZING each tour... Current: [[1, 0, 12, 2, 16, 5, 3, 1], [1, 7, 20, 19, 17, 6, 1], [1, 9, 15, 14, 23, 1], [1, 8, 4, 1]] [1] Cost: 1543.364 to 1525.828 | Optimized: [1, 12, 2, 16, 5, 3, 0, 1] [2] Cost: 1570.459 to 1503.500 | Optimized: [1, 7, 20, 6, 17, 19, 1] [3] Cost: 1819.169 to 1816.316 | Optimized: [1, 9, 15, 23, 14, 1] [4] Cost: 717.471 to 715.744 | Optimized: [1, 4, 8, 1] ACO RESULTS [1/300 vol./1525.828 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Frankfurt Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [2/300 vol./1503.500 km] Berlin Hbf -> Dresden Hbf -> Würzburg Hbf -> Stuttgart Hbf -> Mannheim Hbf -> Mainz Hbf --> Berlin Hbf [3/285 vol./1816.316 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Freiburg Hbf -> Karlsruhe Hbf --> Berlin Hbf [4/130 vol./ 715.744 km] Berlin Hbf -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5561.388 km.