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: 20 customers
- Kassel-Wilhelmshöhe (45 vol.)
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (75 vol.)
- Aachen Hbf (100 vol.)
- Stuttgart Hbf (60 vol.)
- Hamburg Hbf (50 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (30 vol.)
- Dortmund Hbf (35 vol.)
- Nürnberg Hbf (55 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (30 vol.)
- Köln Hbf (25 vol.)
- Mannheim Hbf (65 vol.)
- Mainz Hbf (70 vol.)
- Würzburg Hbf (20 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (35 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1409.247 km
LOAD: 290 vol.
- Frankfurt Hbf | 95 vol.
- Mainz Hbf | 70 vol.
- Mannheim Hbf | 65 vol.
- Karlsruhe Hbf | 40 vol.
- Würzburg Hbf | 20 vol.
Tour 2
COST: 1419.144 km
LOAD: 300 vol.
- Köln Hbf | 25 vol.
- Aachen Hbf | 100 vol.
- Düsseldorf Hbf | 65 vol.
- Dortmund Hbf | 35 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Leipzig Hbf | 30 vol.
Tour 3
COST: 1997.55 km
LOAD: 300 vol.
- Nürnberg Hbf | 55 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 60 vol.
- Freiburg Hbf | 60 vol.
- Saarbrücken Hbf | 60 vol.
- Osnabrück Hbf | 35 vol.
Tour 4
COST: 805.867 km
LOAD: 225 vol.
- Hannover Hbf | 75 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 50 vol.
LOAD: 290 vol.
- Frankfurt Hbf | 95 vol.
- Mainz Hbf | 70 vol.
- Mannheim Hbf | 65 vol.
- Karlsruhe Hbf | 40 vol.
- Würzburg Hbf | 20 vol.
LOAD: 300 vol.
- Köln Hbf | 25 vol.
- Aachen Hbf | 100 vol.
- Düsseldorf Hbf | 65 vol.
- Dortmund Hbf | 35 vol.
- Kassel-Wilhelmshöhe | 45 vol.
- Leipzig Hbf | 30 vol.
LOAD: 300 vol.
- Nürnberg Hbf | 55 vol.
- Ulm Hbf | 30 vol.
- Stuttgart Hbf | 60 vol.
- Freiburg Hbf | 60 vol.
- Saarbrücken Hbf | 60 vol.
- Osnabrück Hbf | 35 vol.
LOAD: 225 vol.
- Hannover Hbf | 75 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 50 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: 1115 vol. | Vehicle capacity: 300 vol. Loads: [45, 0, 65, 95, 75, 100, 60, 0, 50, 0, 100, 30, 35, 55, 40, 30, 25, 65, 0, 70, 20, 60, 35, 60] ITERATION Generation: #1 Best cost: 6774.405 | Path: [1, 0, 22, 4, 10, 12, 1, 11, 20, 13, 6, 15, 14, 17, 1, 8, 2, 16, 5, 21, 1, 3, 19, 23, 1] Best cost: 6464.061 | Path: [1, 3, 19, 17, 14, 15, 1, 11, 4, 10, 22, 12, 16, 1, 0, 20, 13, 6, 23, 21, 1, 8, 2, 5, 1] Best cost: 6405.190 | Path: [1, 4, 10, 8, 22, 12, 1, 11, 13, 20, 3, 19, 16, 1, 0, 2, 5, 21, 15, 1, 17, 14, 23, 6, 1] Best cost: 6253.306 | Path: [1, 5, 16, 2, 12, 22, 20, 1, 11, 0, 4, 10, 8, 1, 13, 6, 14, 17, 19, 1, 15, 23, 21, 3, 1] Best cost: 6247.568 | Path: [1, 13, 20, 3, 19, 14, 1, 11, 0, 22, 4, 10, 1, 8, 12, 2, 16, 5, 1, 15, 6, 17, 21, 23, 1] Best cost: 6195.871 | Path: [1, 15, 6, 14, 17, 19, 20, 1, 11, 0, 4, 10, 22, 1, 8, 12, 2, 16, 5, 1, 13, 3, 21, 23, 1] Best cost: 6087.256 | Path: [1, 17, 14, 6, 15, 20, 13, 11, 1, 0, 16, 2, 12, 22, 4, 1, 8, 10, 5, 1, 3, 19, 21, 23, 1] Best cost: 6006.897 | Path: [1, 0, 12, 2, 16, 5, 20, 1, 11, 13, 15, 6, 14, 17, 1, 8, 10, 4, 22, 1, 19, 3, 21, 23, 1] Best cost: 6006.562 | Path: [1, 0, 12, 2, 16, 5, 20, 1, 11, 13, 6, 14, 17, 15, 1, 8, 10, 22, 4, 1, 19, 3, 21, 23, 1] Best cost: 5827.138 | Path: [1, 15, 6, 14, 17, 19, 20, 1, 11, 0, 12, 2, 16, 5, 1, 8, 10, 22, 4, 1, 13, 3, 21, 23, 1] Best cost: 5811.332 | Path: [1, 0, 12, 2, 16, 5, 20, 1, 11, 13, 15, 6, 14, 17, 1, 4, 22, 10, 8, 1, 3, 19, 21, 23, 1] Generation: #2 Best cost: 5707.511 | Path: [1, 14, 17, 19, 3, 20, 1, 11, 0, 12, 2, 16, 5, 1, 13, 15, 6, 23, 21, 22, 1, 4, 10, 8, 1] OPTIMIZING each tour... Current: [[1, 14, 17, 19, 3, 20, 1], [1, 11, 0, 12, 2, 16, 5, 1], [1, 13, 15, 6, 23, 21, 22, 1], [1, 4, 10, 8, 1]] [1] Cost: 1467.767 to 1409.247 | Optimized: [1, 3, 19, 17, 14, 20, 1] [2] Cost: 1436.327 to 1419.144 | Optimized: [1, 16, 5, 2, 12, 0, 11, 1] ACO RESULTS [1/290 vol./1409.247 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Würzburg Hbf --> Berlin Hbf [2/300 vol./1419.144 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Kassel-Wilhelmshöhe -> Leipzig Hbf --> Berlin Hbf [3/300 vol./1997.550 km] Berlin Hbf -> Nürnberg Hbf -> Ulm Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Osnabrück Hbf --> Berlin Hbf [4/225 vol./ 805.867 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5631.808 km.