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.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (50 vol.)
- Stuttgart Hbf (65 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (40 vol.)
- Leipzig Hbf (100 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (45 vol.)
- Ulm Hbf (65 vol.)
- Köln Hbf (95 vol.)
- Mannheim Hbf (95 vol.)
- Kiel Hbf (40 vol.)
- Mainz Hbf (40 vol.)
- Würzburg Hbf (80 vol.)
- Saarbrücken Hbf (70 vol.)
- Osnabrück Hbf (90 vol.)
Tour 1
COST: 1513.495 km
LOAD: 300 vol.
- Nürnberg Hbf | 45 vol.
- Würzburg Hbf | 80 vol.
- Frankfurt Hbf | 95 vol.
- Mainz Hbf | 40 vol.
- Hamburg Hbf | 40 vol.
Tour 2
COST: 1355.175 km
LOAD: 300 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Kiel Hbf | 40 vol.
Tour 3
COST: 1212.545 km
LOAD: 300 vol.
- Dortmund Hbf | 65 vol.
- Köln Hbf | 95 vol.
- Osnabrück Hbf | 90 vol.
- Hannover Hbf | 50 vol.
Tour 4
COST: 1690.436 km
LOAD: 295 vol.
- Mannheim Hbf | 95 vol.
- Saarbrücken Hbf | 70 vol.
- Stuttgart Hbf | 65 vol.
- Ulm Hbf | 65 vol.
LOAD: 300 vol.
- Nürnberg Hbf | 45 vol.
- Würzburg Hbf | 80 vol.
- Frankfurt Hbf | 95 vol.
- Mainz Hbf | 40 vol.
- Hamburg Hbf | 40 vol.
LOAD: 300 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Kiel Hbf | 40 vol.
LOAD: 300 vol.
- Dortmund Hbf | 65 vol.
- Köln Hbf | 95 vol.
- Osnabrück Hbf | 90 vol.
- Hannover Hbf | 50 vol.
LOAD: 295 vol.
- Mannheim Hbf | 95 vol.
- Saarbrücken Hbf | 70 vol.
- Stuttgart Hbf | 65 vol.
- Ulm Hbf | 65 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: 1195 vol. | Vehicle capacity: 300 vol. Loads: [65, 0, 0, 95, 50, 0, 65, 95, 40, 0, 0, 100, 65, 45, 0, 65, 95, 95, 40, 40, 80, 70, 90, 0] ITERATION Generation: #1 Best cost: 7349.962 | Path: [1, 0, 12, 16, 19, 1, 11, 7, 13, 4, 1, 8, 18, 22, 3, 1, 20, 6, 15, 21, 1, 17, 1] Best cost: 5872.768 | Path: [1, 3, 19, 17, 21, 1, 7, 11, 0, 8, 1, 4, 22, 12, 16, 1, 13, 20, 6, 15, 18, 1] Best cost: 5791.039 | Path: [1, 13, 20, 3, 19, 18, 1, 7, 11, 0, 8, 1, 4, 22, 12, 16, 1, 15, 6, 17, 21, 1] Generation: #4 Best cost: 5789.495 | Path: [1, 13, 20, 3, 19, 8, 1, 7, 11, 0, 18, 1, 22, 12, 16, 4, 1, 15, 6, 17, 21, 1] OPTIMIZING each tour... Current: [[1, 13, 20, 3, 19, 8, 1], [1, 7, 11, 0, 18, 1], [1, 22, 12, 16, 4, 1], [1, 15, 6, 17, 21, 1]] [3] Cost: 1219.375 to 1212.545 | Optimized: [1, 12, 16, 22, 4, 1] [4] Cost: 1701.450 to 1690.436 | Optimized: [1, 17, 21, 6, 15, 1] ACO RESULTS [1/300 vol./1513.495 km] Berlin Hbf -> Nürnberg Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Mainz Hbf -> Hamburg Hbf --> Berlin Hbf [2/300 vol./1355.175 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Kiel Hbf --> Berlin Hbf [3/300 vol./1212.545 km] Berlin Hbf -> Dortmund Hbf -> Köln Hbf -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [4/295 vol./1690.436 km] Berlin Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5771.651 km.