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: 21 customers
- Kassel-Wilhelmshöhe (50 vol.)
- Düsseldorf Hbf (100 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (75 vol.)
- Dresden Hbf (100 vol.)
- Hamburg Hbf (95 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (95 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (35 vol.)
- Ulm Hbf (80 vol.)
- Köln Hbf (30 vol.)
- Mannheim Hbf (35 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (40 vol.)
- Würzburg Hbf (60 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (100 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 858.167 km
LOAD: 295 vol.
- Dresden Hbf | 100 vol.
- Leipzig Hbf | 95 vol.
- Hannover Hbf | 100 vol.
Tour 2
COST: 941.643 km
LOAD: 290 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 95 vol.
Tour 3
COST: 1581.992 km
LOAD: 275 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 70 vol.
- Düsseldorf Hbf | 100 vol.
- Dortmund Hbf | 50 vol.
- Kiel Hbf | 25 vol.
Tour 4
COST: 1590.532 km
LOAD: 280 vol.
- Nürnberg Hbf | 35 vol.
- Mannheim Hbf | 35 vol.
- Saarbrücken Hbf | 60 vol.
- Mainz Hbf | 40 vol.
- Frankfurt Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 50 vol.
Tour 5
COST: 1720.175 km
LOAD: 290 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 75 vol.
- Freiburg Hbf | 75 vol.
- Würzburg Hbf | 60 vol.
LOAD: 295 vol.
- Dresden Hbf | 100 vol.
- Leipzig Hbf | 95 vol.
- Hannover Hbf | 100 vol.
LOAD: 290 vol.
- Osnabrück Hbf | 100 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 95 vol.
LOAD: 275 vol.
- Köln Hbf | 30 vol.
- Aachen Hbf | 70 vol.
- Düsseldorf Hbf | 100 vol.
- Dortmund Hbf | 50 vol.
- Kiel Hbf | 25 vol.
LOAD: 280 vol.
- Nürnberg Hbf | 35 vol.
- Mannheim Hbf | 35 vol.
- Saarbrücken Hbf | 60 vol.
- Mainz Hbf | 40 vol.
- Frankfurt Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 50 vol.
LOAD: 290 vol.
- Ulm Hbf | 80 vol.
- Stuttgart Hbf | 75 vol.
- Freiburg Hbf | 75 vol.
- Würzburg Hbf | 60 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: 1430 vol. | Vehicle capacity: 300 vol. Loads: [50, 0, 100, 60, 100, 70, 75, 100, 95, 0, 95, 95, 50, 35, 0, 80, 30, 35, 25, 40, 60, 60, 100, 75] ITERATION Generation: #1 Best cost: 7844.582 | Path: [1, 0, 12, 2, 16, 5, 1, 11, 7, 20, 13, 1, 8, 18, 4, 3, 1, 10, 22, 21, 17, 1, 15, 6, 19, 23, 1] Best cost: 7392.679 | Path: [1, 2, 16, 5, 12, 0, 1, 11, 7, 13, 20, 1, 4, 10, 8, 1, 22, 3, 19, 17, 21, 1, 18, 15, 6, 23, 1] Best cost: 7290.322 | Path: [1, 4, 10, 8, 1, 11, 7, 13, 20, 1, 18, 22, 12, 2, 1, 0, 16, 5, 21, 17, 19, 1, 6, 15, 3, 23, 1] Best cost: 7205.218 | Path: [1, 8, 18, 10, 12, 16, 1, 7, 11, 4, 1, 3, 19, 17, 21, 6, 1, 13, 20, 15, 23, 0, 1, 22, 2, 5, 1] Best cost: 7143.644 | Path: [1, 7, 11, 4, 1, 8, 18, 10, 12, 16, 1, 0, 20, 13, 6, 15, 1, 22, 2, 5, 1, 19, 3, 17, 21, 23, 1] Best cost: 6978.345 | Path: [1, 20, 6, 15, 13, 17, 1, 7, 11, 4, 1, 8, 10, 22, 1, 18, 12, 2, 16, 5, 1, 0, 3, 19, 21, 23, 1] Best cost: 6969.780 | Path: [1, 7, 11, 4, 1, 8, 18, 10, 12, 16, 1, 0, 17, 19, 3, 20, 13, 1, 22, 2, 5, 1, 15, 6, 23, 21, 1] Best cost: 6948.715 | Path: [1, 7, 11, 4, 1, 8, 10, 22, 1, 3, 19, 17, 21, 23, 16, 1, 12, 2, 5, 0, 18, 1, 13, 20, 6, 15, 1] Best cost: 6943.656 | Path: [1, 15, 6, 17, 19, 3, 1, 11, 7, 13, 20, 1, 4, 10, 8, 1, 18, 22, 12, 2, 1, 0, 16, 5, 21, 23, 1] Generation: #2 Best cost: 6859.924 | Path: [1, 5, 2, 16, 12, 0, 1, 7, 11, 4, 1, 8, 10, 22, 1, 18, 19, 3, 17, 21, 23, 1, 13, 20, 6, 15, 1] Generation: #4 Best cost: 6846.930 | Path: [1, 22, 10, 8, 1, 7, 11, 4, 1, 20, 3, 19, 17, 21, 16, 1, 0, 12, 2, 5, 18, 1, 15, 6, 23, 13, 1] Best cost: 6799.697 | Path: [1, 22, 10, 8, 1, 7, 11, 4, 1, 0, 12, 2, 16, 5, 1, 18, 3, 19, 17, 21, 23, 1, 13, 20, 6, 15, 1] Generation: #5 Best cost: 6793.537 | Path: [1, 22, 10, 8, 1, 7, 11, 4, 1, 0, 12, 2, 16, 5, 1, 18, 3, 19, 17, 21, 23, 1, 15, 6, 20, 13, 1] Generation: #6 Best cost: 6780.607 | Path: [1, 7, 11, 4, 1, 8, 10, 22, 1, 18, 12, 2, 16, 5, 1, 0, 3, 19, 17, 21, 13, 1, 15, 6, 23, 20, 1] OPTIMIZING each tour... Current: [[1, 7, 11, 4, 1], [1, 8, 10, 22, 1], [1, 18, 12, 2, 16, 5, 1], [1, 0, 3, 19, 17, 21, 13, 1], [1, 15, 6, 23, 20, 1]] [2] Cost: 947.067 to 941.643 | Optimized: [1, 22, 10, 8, 1] [3] Cost: 1601.238 to 1581.992 | Optimized: [1, 16, 5, 2, 12, 18, 1] [4] Cost: 1653.960 to 1590.532 | Optimized: [1, 13, 17, 21, 19, 3, 0, 1] ACO RESULTS [1/295 vol./ 858.167 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf --> Berlin Hbf [2/290 vol./ 941.643 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/275 vol./1581.992 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Kiel Hbf --> Berlin Hbf [4/280 vol./1590.532 km] Berlin Hbf -> Nürnberg Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [5/290 vol./1720.175 km] Berlin Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6692.509 km.