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: 16 customers
- Kassel-Wilhelmshöhe (75 vol.)
- Düsseldorf Hbf (55 vol.)
- Hannover Hbf (30 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (95 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (70 vol.)
- Bremen Hbf (85 vol.)
- Leipzig Hbf (75 vol.)
- Karlsruhe Hbf (45 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (65 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (80 vol.)
- Osnabrück Hbf (70 vol.)
Tour 1
COST: 1572.784 km
LOAD: 275 vol.
- München Hbf | 70 vol.
- Stuttgart Hbf | 95 vol.
- Karlsruhe Hbf | 45 vol.
- Mannheim Hbf | 65 vol.
Tour 2
COST: 1203.248 km
LOAD: 290 vol.
- Leipzig Hbf | 75 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Osnabrück Hbf | 70 vol.
- Hannover Hbf | 30 vol.
- Hamburg Hbf | 40 vol.
Tour 3
COST: 1521.928 km
LOAD: 300 vol.
- Düsseldorf Hbf | 55 vol.
- Aachen Hbf | 80 vol.
- Köln Hbf | 30 vol.
- Mainz Hbf | 55 vol.
- Würzburg Hbf | 80 vol.
Tour 4
COST: 944.451 km
LOAD: 120 vol.
- Kiel Hbf | 35 vol.
- Bremen Hbf | 85 vol.
LOAD: 275 vol.
- München Hbf | 70 vol.
- Stuttgart Hbf | 95 vol.
- Karlsruhe Hbf | 45 vol.
- Mannheim Hbf | 65 vol.
LOAD: 290 vol.
- Leipzig Hbf | 75 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Osnabrück Hbf | 70 vol.
- Hannover Hbf | 30 vol.
- Hamburg Hbf | 40 vol.
LOAD: 300 vol.
- Düsseldorf Hbf | 55 vol.
- Aachen Hbf | 80 vol.
- Köln Hbf | 30 vol.
- Mainz Hbf | 55 vol.
- Würzburg Hbf | 80 vol.
LOAD: 120 vol.
- Kiel Hbf | 35 vol.
- Bremen Hbf | 85 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: 985 vol. | Vehicle capacity: 300 vol. Loads: [75, 0, 55, 0, 30, 80, 95, 0, 40, 70, 85, 75, 0, 0, 45, 0, 30, 65, 35, 55, 80, 0, 70, 0] ITERATION Generation: #1 Best cost: 6042.832 | Path: [1, 0, 22, 10, 8, 4, 1, 11, 20, 19, 17, 1, 18, 16, 2, 5, 14, 1, 9, 6, 1] Best cost: 5952.493 | Path: [1, 2, 16, 5, 19, 17, 1, 11, 0, 20, 14, 1, 4, 10, 8, 18, 22, 1, 6, 9, 1] Best cost: 5874.219 | Path: [1, 5, 2, 16, 19, 17, 1, 11, 4, 10, 8, 18, 1, 22, 0, 20, 14, 1, 9, 6, 1] Best cost: 5687.784 | Path: [1, 9, 6, 14, 17, 1, 11, 4, 22, 10, 8, 1, 0, 5, 2, 16, 19, 1, 20, 18, 1] Best cost: 5637.465 | Path: [1, 9, 6, 14, 17, 1, 11, 4, 22, 10, 8, 1, 18, 0, 2, 16, 5, 1, 20, 19, 1] Best cost: 5626.181 | Path: [1, 6, 14, 17, 19, 16, 1, 11, 4, 10, 8, 18, 1, 22, 0, 2, 5, 1, 20, 9, 1] Best cost: 5323.230 | Path: [1, 16, 2, 5, 19, 17, 1, 11, 4, 10, 8, 18, 1, 20, 14, 6, 9, 1, 0, 22, 1] Generation: #2 Best cost: 5312.387 | Path: [1, 5, 2, 16, 19, 17, 1, 11, 4, 10, 8, 18, 1, 9, 6, 14, 20, 1, 0, 22, 1] Best cost: 5282.015 | Path: [1, 9, 6, 14, 17, 1, 11, 0, 22, 4, 8, 1, 20, 19, 16, 2, 5, 1, 18, 10, 1] OPTIMIZING each tour... Current: [[1, 9, 6, 14, 17, 1], [1, 11, 0, 22, 4, 8, 1], [1, 20, 19, 16, 2, 5, 1], [1, 18, 10, 1]] [3] Cost: 1561.532 to 1521.928 | Optimized: [1, 2, 5, 16, 19, 20, 1] ACO RESULTS [1/275 vol./1572.784 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Berlin Hbf [2/290 vol./1203.248 km] Berlin Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf [3/300 vol./1521.928 km] Berlin Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Köln Hbf -> Mainz Hbf -> Würzburg Hbf --> Berlin Hbf [4/120 vol./ 944.451 km] Berlin Hbf -> Kiel Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5242.411 km.