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: 19 customers
- Kassel-Wilhelmshöhe (65 vol.)
- Düsseldorf Hbf (60 vol.)
- Hannover Hbf (20 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (75 vol.)
- Dresden Hbf (30 vol.)
- München Hbf (45 vol.)
- Bremen Hbf (65 vol.)
- Leipzig Hbf (55 vol.)
- Dortmund Hbf (35 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (75 vol.)
- Ulm Hbf (45 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (35 vol.)
- Kiel Hbf (40 vol.)
- Mainz Hbf (30 vol.)
- Würzburg Hbf (100 vol.)
- Osnabrück Hbf (80 vol.)
Tour 1
COST: 1676.957 km
LOAD: 295 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 45 vol.
- Stuttgart Hbf | 75 vol.
- Karlsruhe Hbf | 75 vol.
- Mannheim Hbf | 35 vol.
- Hannover Hbf | 20 vol.
Tour 2
COST: 1427.943 km
LOAD: 300 vol.
- Mainz Hbf | 30 vol.
- Würzburg Hbf | 100 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 55 vol.
- Dresden Hbf | 30 vol.
Tour 3
COST: 1370.534 km
LOAD: 290 vol.
- Dortmund Hbf | 35 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 65 vol.
Tour 4
COST: 1095.698 km
LOAD: 185 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 65 vol.
- Kiel Hbf | 40 vol.
LOAD: 295 vol.
- München Hbf | 45 vol.
- Ulm Hbf | 45 vol.
- Stuttgart Hbf | 75 vol.
- Karlsruhe Hbf | 75 vol.
- Mannheim Hbf | 35 vol.
- Hannover Hbf | 20 vol.
LOAD: 300 vol.
- Mainz Hbf | 30 vol.
- Würzburg Hbf | 100 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 55 vol.
- Dresden Hbf | 30 vol.
LOAD: 290 vol.
- Dortmund Hbf | 35 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 65 vol.
LOAD: 185 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 65 vol.
- Kiel Hbf | 40 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: 1070 vol. | Vehicle capacity: 300 vol. Loads: [65, 0, 60, 0, 20, 70, 75, 30, 0, 45, 65, 55, 35, 85, 75, 45, 60, 35, 40, 30, 100, 0, 80, 0] ITERATION Generation: #1 Best cost: 6447.562 | Path: [1, 0, 12, 2, 16, 5, 1, 11, 7, 13, 20, 19, 1, 4, 10, 22, 17, 14, 1, 18, 6, 15, 9, 1] Best cost: 6262.761 | Path: [1, 4, 22, 12, 2, 16, 19, 1, 11, 7, 13, 20, 1, 18, 10, 0, 5, 17, 1, 9, 15, 6, 14, 1] Best cost: 6062.326 | Path: [1, 7, 11, 0, 22, 10, 1, 4, 12, 2, 16, 5, 19, 1, 18, 20, 13, 9, 1, 17, 14, 6, 15, 1] Best cost: 5993.192 | Path: [1, 9, 15, 6, 14, 17, 4, 1, 11, 7, 13, 20, 19, 1, 22, 12, 2, 16, 0, 1, 18, 10, 5, 1] Best cost: 5834.484 | Path: [1, 9, 15, 6, 14, 17, 4, 1, 11, 7, 13, 20, 19, 1, 22, 2, 16, 5, 1, 0, 12, 10, 18, 1] Best cost: 5817.152 | Path: [1, 0, 12, 2, 16, 5, 1, 11, 7, 4, 22, 10, 18, 1, 20, 13, 9, 15, 1, 19, 17, 14, 6, 1] Best cost: 5793.278 | Path: [1, 5, 16, 2, 12, 0, 1, 7, 11, 4, 10, 22, 18, 1, 15, 6, 14, 17, 19, 1, 13, 20, 9, 1] Best cost: 5717.956 | Path: [1, 7, 11, 4, 22, 10, 18, 1, 20, 13, 9, 15, 1, 0, 12, 2, 16, 5, 1, 19, 17, 14, 6, 1] Generation: #2 Best cost: 5609.074 | Path: [1, 9, 15, 6, 14, 17, 4, 1, 11, 7, 13, 20, 19, 1, 0, 12, 2, 16, 5, 1, 18, 10, 22, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 14, 17, 4, 1], [1, 11, 7, 13, 20, 19, 1], [1, 0, 12, 2, 16, 5, 1], [1, 18, 10, 22, 1]] [2] Cost: 1458.199 to 1427.943 | Optimized: [1, 19, 20, 13, 11, 7, 1] [3] Cost: 1372.044 to 1370.534 | Optimized: [1, 12, 2, 16, 5, 0, 1] [4] Cost: 1101.874 to 1095.698 | Optimized: [1, 22, 10, 18, 1] ACO RESULTS [1/295 vol./1676.957 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Hannover Hbf --> Berlin Hbf [2/300 vol./1427.943 km] Berlin Hbf -> Mainz Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/290 vol./1370.534 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/185 vol./1095.698 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5571.132 km.