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
- Kassel-Wilhelmshöhe (75 vol.)
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (30 vol.)
- Aachen Hbf (95 vol.)
- Stuttgart Hbf (70 vol.)
- Dresden Hbf (75 vol.)
- Hamburg Hbf (40 vol.)
- Leipzig Hbf (60 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (90 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (60 vol.)
- Mannheim Hbf (95 vol.)
- Würzburg Hbf (40 vol.)
- Osnabrück Hbf (100 vol.)
Tour 1
COST: 1365.481 km
LOAD: 285 vol.
- Frankfurt Hbf | 55 vol.
- Mannheim Hbf | 95 vol.
- Karlsruhe Hbf | 95 vol.
- Würzburg Hbf | 40 vol.
Tour 2
COST: 1133.433 km
LOAD: 265 vol.
- Osnabrück Hbf | 100 vol.
- Hannover Hbf | 30 vol.
- Leipzig Hbf | 60 vol.
- Dresden Hbf | 75 vol.
Tour 3
COST: 1483.955 km
LOAD: 260 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Dortmund Hbf | 50 vol.
- Aachen Hbf | 95 vol.
- Hamburg Hbf | 40 vol.
Tour 4
COST: 1352.477 km
LOAD: 220 vol.
- Ulm Hbf | 60 vol.
- Stuttgart Hbf | 70 vol.
- Nürnberg Hbf | 90 vol.
LOAD: 285 vol.
- Frankfurt Hbf | 55 vol.
- Mannheim Hbf | 95 vol.
- Karlsruhe Hbf | 95 vol.
- Würzburg Hbf | 40 vol.
LOAD: 265 vol.
- Osnabrück Hbf | 100 vol.
- Hannover Hbf | 30 vol.
- Leipzig Hbf | 60 vol.
- Dresden Hbf | 75 vol.
LOAD: 260 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Dortmund Hbf | 50 vol.
- Aachen Hbf | 95 vol.
- Hamburg Hbf | 40 vol.
LOAD: 220 vol.
- Ulm Hbf | 60 vol.
- Stuttgart Hbf | 70 vol.
- Nürnberg 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: 1030 vol. | Vehicle capacity: 300 vol. Loads: [75, 0, 0, 55, 30, 95, 70, 75, 40, 0, 0, 60, 50, 90, 95, 60, 0, 95, 0, 0, 40, 0, 100, 0] ITERATION Generation: #1 Best cost: 5754.046 | Path: [1, 0, 12, 22, 4, 8, 1, 7, 11, 20, 13, 1, 17, 14, 6, 1, 3, 5, 15, 1] Best cost: 5497.404 | Path: [1, 5, 12, 22, 4, 1, 7, 11, 20, 13, 1, 8, 0, 3, 17, 1, 15, 6, 14, 1] Best cost: 5474.313 | Path: [1, 14, 17, 3, 20, 1, 7, 11, 4, 22, 1, 12, 5, 0, 8, 1, 13, 15, 6, 1] Best cost: 5413.979 | Path: [1, 3, 17, 14, 20, 1, 7, 11, 4, 22, 1, 8, 0, 12, 5, 1, 13, 6, 15, 1] Generation: #2 Best cost: 5341.371 | Path: [1, 3, 17, 14, 20, 1, 7, 11, 4, 22, 1, 8, 12, 5, 0, 1, 13, 6, 15, 1] OPTIMIZING each tour... Current: [[1, 3, 17, 14, 20, 1], [1, 7, 11, 4, 22, 1], [1, 8, 12, 5, 0, 1], [1, 13, 6, 15, 1]] [2] Cost: 1134.711 to 1133.433 | Optimized: [1, 22, 4, 11, 7, 1] [3] Cost: 1484.634 to 1483.955 | Optimized: [1, 0, 12, 5, 8, 1] [4] Cost: 1356.545 to 1352.477 | Optimized: [1, 15, 6, 13, 1] ACO RESULTS [1/285 vol./1365.481 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Würzburg Hbf --> Berlin Hbf [2/265 vol./1133.433 km] Berlin Hbf -> Osnabrück Hbf -> Hannover Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/260 vol./1483.955 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Aachen Hbf -> Hamburg Hbf --> Berlin Hbf [4/220 vol./1352.477 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5335.346 km.