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 (75 vol.)
- Düsseldorf Hbf (25 vol.)
- Hannover Hbf (100 vol.)
- Stuttgart Hbf (65 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (100 vol.)
- Bremen Hbf (20 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (80 vol.)
- Karlsruhe Hbf (25 vol.)
- Ulm Hbf (90 vol.)
- Köln Hbf (85 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (45 vol.)
- Mainz Hbf (80 vol.)
- Würzburg Hbf (45 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (45 vol.)
Tour 1
COST: 1428.927 km
LOAD: 300 vol.
- Mainz Hbf | 80 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 25 vol.
- Stuttgart Hbf | 65 vol.
- Würzburg Hbf | 45 vol.
Tour 2
COST: 1007.951 km
LOAD: 285 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 50 vol.
- Hannover Hbf | 100 vol.
- Hamburg Hbf | 100 vol.
Tour 3
COST: 1283.046 km
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Dortmund Hbf | 80 vol.
- Düsseldorf Hbf | 25 vol.
- Köln Hbf | 85 vol.
- Osnabrück Hbf | 20 vol.
Tour 4
COST: 2227.928 km
LOAD: 300 vol.
- Kiel Hbf | 45 vol.
- Bremen Hbf | 20 vol.
- Saarbrücken Hbf | 100 vol.
- Freiburg Hbf | 45 vol.
- Ulm Hbf | 90 vol.
LOAD: 300 vol.
- Mainz Hbf | 80 vol.
- Mannheim Hbf | 85 vol.
- Karlsruhe Hbf | 25 vol.
- Stuttgart Hbf | 65 vol.
- Würzburg Hbf | 45 vol.
LOAD: 285 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 50 vol.
- Hannover Hbf | 100 vol.
- Hamburg Hbf | 100 vol.
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Dortmund Hbf | 80 vol.
- Düsseldorf Hbf | 25 vol.
- Köln Hbf | 85 vol.
- Osnabrück Hbf | 20 vol.
LOAD: 300 vol.
- Kiel Hbf | 45 vol.
- Bremen Hbf | 20 vol.
- Saarbrücken Hbf | 100 vol.
- Freiburg Hbf | 45 vol.
- Ulm Hbf | 90 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: 1170 vol. | Vehicle capacity: 300 vol. Loads: [75, 0, 25, 0, 100, 0, 65, 35, 100, 0, 20, 50, 80, 0, 25, 90, 85, 85, 45, 80, 45, 100, 20, 45] ITERATION Generation: #1 Best cost: 8152.285 | Path: [1, 0, 12, 2, 16, 22, 1, 7, 11, 4, 10, 18, 20, 1, 8, 21, 17, 1, 6, 14, 19, 23, 1, 15, 1] Best cost: 6775.327 | Path: [1, 2, 16, 12, 22, 10, 18, 14, 1, 7, 11, 4, 8, 1, 0, 17, 19, 20, 1, 15, 6, 23, 21, 1] Best cost: 6233.280 | Path: [1, 4, 22, 10, 8, 18, 1, 11, 7, 19, 17, 14, 2, 1, 0, 12, 16, 20, 1, 15, 6, 23, 21, 1] Best cost: 6109.394 | Path: [1, 6, 14, 17, 19, 20, 1, 11, 7, 4, 8, 1, 0, 12, 2, 16, 22, 1, 18, 10, 21, 23, 15, 1] Generation: #4 Best cost: 6050.928 | Path: [1, 20, 6, 14, 17, 19, 1, 11, 7, 4, 8, 1, 0, 12, 2, 16, 22, 1, 18, 10, 21, 23, 15, 1] OPTIMIZING each tour... Current: [[1, 20, 6, 14, 17, 19, 1], [1, 11, 7, 4, 8, 1], [1, 0, 12, 2, 16, 22, 1], [1, 18, 10, 21, 23, 15, 1]] [1] Cost: 1432.807 to 1428.927 | Optimized: [1, 19, 17, 14, 6, 20, 1] [2] Cost: 1107.147 to 1007.951 | Optimized: [1, 7, 11, 4, 8, 1] ACO RESULTS [1/300 vol./1428.927 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [2/285 vol./1007.951 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Hamburg Hbf --> Berlin Hbf [3/285 vol./1283.046 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Osnabrück Hbf --> Berlin Hbf [4/300 vol./2227.928 km] Berlin Hbf -> Kiel Hbf -> Bremen Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Ulm Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5947.852 km.