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 (20 vol.)
- Düsseldorf Hbf (60 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (60 vol.)
- Stuttgart Hbf (80 vol.)
- Dresden Hbf (45 vol.)
- München Hbf (85 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (65 vol.)
- Dortmund Hbf (25 vol.)
- Karlsruhe Hbf (100 vol.)
- Köln Hbf (90 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (40 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (95 vol.)
- Osnabrück Hbf (35 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1422.288 km
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Dortmund Hbf | 25 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 90 vol.
- Aachen Hbf | 60 vol.
- Osnabrück Hbf | 35 vol.
Tour 2
COST: 1476.084 km
LOAD: 285 vol.
- Mainz Hbf | 40 vol.
- Mannheim Hbf | 75 vol.
- Würzburg Hbf | 60 vol.
- Leipzig Hbf | 65 vol.
- Dresden Hbf | 45 vol.
Tour 3
COST: 959.922 km
LOAD: 280 vol.
- Hannover Hbf | 95 vol.
- Bremen Hbf | 95 vol.
- Kiel Hbf | 90 vol.
Tour 4
COST: 1738.161 km
LOAD: 280 vol.
- Saarbrücken Hbf | 95 vol.
- Freiburg Hbf | 85 vol.
- Karlsruhe Hbf | 100 vol.
Tour 5
COST: 1430.64 km
LOAD: 165 vol.
- München Hbf | 85 vol.
- Stuttgart Hbf | 80 vol.
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Dortmund Hbf | 25 vol.
- Düsseldorf Hbf | 60 vol.
- Köln Hbf | 90 vol.
- Aachen Hbf | 60 vol.
- Osnabrück Hbf | 35 vol.
LOAD: 285 vol.
- Mainz Hbf | 40 vol.
- Mannheim Hbf | 75 vol.
- Würzburg Hbf | 60 vol.
- Leipzig Hbf | 65 vol.
- Dresden Hbf | 45 vol.
LOAD: 280 vol.
- Hannover Hbf | 95 vol.
- Bremen Hbf | 95 vol.
- Kiel Hbf | 90 vol.
LOAD: 280 vol.
- Saarbrücken Hbf | 95 vol.
- Freiburg Hbf | 85 vol.
- Karlsruhe Hbf | 100 vol.
LOAD: 165 vol.
- München Hbf | 85 vol.
- Stuttgart Hbf | 80 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: 1300 vol. | Vehicle capacity: 300 vol. Loads: [20, 0, 60, 0, 95, 60, 80, 45, 0, 85, 95, 65, 25, 0, 100, 0, 90, 75, 90, 40, 60, 95, 35, 85] ITERATION Generation: #1 Best cost: 7833.388 | Path: [1, 0, 22, 12, 2, 16, 5, 1, 7, 11, 4, 10, 1, 18, 20, 6, 19, 1, 17, 14, 21, 1, 9, 23, 1] Best cost: 7765.211 | Path: [1, 2, 16, 5, 12, 22, 0, 1, 7, 11, 4, 10, 1, 18, 17, 14, 1, 9, 6, 20, 19, 1, 21, 23, 1] Best cost: 7572.563 | Path: [1, 4, 10, 22, 12, 0, 1, 7, 11, 9, 6, 1, 18, 16, 2, 5, 1, 19, 17, 14, 23, 1, 20, 21, 1] Best cost: 7535.621 | Path: [1, 12, 2, 16, 5, 19, 0, 1, 11, 7, 20, 6, 22, 1, 4, 10, 18, 1, 9, 23, 14, 1, 17, 21, 1] Best cost: 7430.964 | Path: [1, 18, 10, 4, 0, 1, 11, 7, 20, 19, 17, 1, 12, 2, 16, 5, 22, 1, 9, 6, 14, 1, 21, 23, 1] Best cost: 7238.987 | Path: [1, 23, 14, 17, 19, 1, 7, 11, 0, 12, 2, 5, 1, 18, 10, 4, 1, 22, 16, 21, 6, 1, 20, 9, 1] Best cost: 7225.452 | Path: [1, 2, 16, 5, 12, 22, 0, 1, 11, 7, 9, 6, 1, 4, 10, 18, 1, 20, 14, 17, 19, 1, 21, 23, 1] Generation: #2 Best cost: 7171.372 | Path: [1, 5, 16, 2, 12, 22, 0, 1, 11, 7, 20, 19, 17, 1, 4, 10, 18, 1, 21, 23, 14, 1, 9, 6, 1] OPTIMIZING each tour... Current: [[1, 5, 16, 2, 12, 22, 0, 1], [1, 11, 7, 20, 19, 17, 1], [1, 4, 10, 18, 1], [1, 21, 23, 14, 1], [1, 9, 6, 1]] [1] Cost: 1510.473 to 1422.288 | Optimized: [1, 0, 12, 2, 16, 5, 22, 1] [2] Cost: 1532.176 to 1476.084 | Optimized: [1, 19, 17, 20, 11, 7, 1] ACO RESULTS [1/290 vol./1422.288 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Osnabrück Hbf --> Berlin Hbf [2/285 vol./1476.084 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Würzburg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/280 vol./ 959.922 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf [4/280 vol./1738.161 km] Berlin Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Karlsruhe Hbf --> Berlin Hbf [5/165 vol./1430.640 km] Berlin Hbf -> München Hbf -> Stuttgart Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7027.095 km.