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: 18 customers
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (100 vol.)
- Hannover Hbf (45 vol.)
- Hamburg Hbf (60 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (80 vol.)
- Leipzig Hbf (55 vol.)
- Dortmund Hbf (45 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (60 vol.)
- Ulm Hbf (90 vol.)
- Mannheim Hbf (80 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (45 vol.)
- Würzburg Hbf (20 vol.)
- Saarbrücken Hbf (75 vol.)
- Osnabrück Hbf (65 vol.)
- Freiburg Hbf (90 vol.)
Tour 1
COST: 1656.619 km
LOAD: 295 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 80 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 90 vol.
- Würzburg Hbf | 20 vol.
Tour 2
COST: 1392.837 km
LOAD: 285 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 90 vol.
- Nürnberg Hbf | 100 vol.
- Leipzig Hbf | 55 vol.
Tour 3
COST: 1107.833 km
LOAD: 270 vol.
- Osnabrück Hbf | 65 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 65 vol.
Tour 4
COST: 1568.205 km
LOAD: 300 vol.
- Frankfurt Hbf | 100 vol.
- Saarbrücken Hbf | 75 vol.
- Düsseldorf Hbf | 35 vol.
- Dortmund Hbf | 45 vol.
- Hannover Hbf | 45 vol.
LOAD: 295 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 80 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 90 vol.
- Würzburg Hbf | 20 vol.
LOAD: 285 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 90 vol.
- Nürnberg Hbf | 100 vol.
- Leipzig Hbf | 55 vol.
LOAD: 270 vol.
- Osnabrück Hbf | 65 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 60 vol.
- Kiel Hbf | 65 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 100 vol.
- Saarbrücken Hbf | 75 vol.
- Düsseldorf Hbf | 35 vol.
- Dortmund Hbf | 45 vol.
- Hannover Hbf | 45 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: 1150 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 35, 100, 45, 0, 0, 0, 60, 40, 80, 55, 45, 100, 60, 90, 0, 80, 65, 45, 20, 75, 65, 90] ITERATION Generation: #1 Best cost: 7852.130 | Path: [1, 2, 12, 22, 10, 8, 1, 11, 4, 18, 15, 9, 1, 13, 20, 3, 19, 1, 17, 14, 23, 1, 21, 1] Best cost: 6748.819 | Path: [1, 3, 19, 17, 14, 1, 11, 4, 10, 22, 12, 1, 8, 18, 2, 21, 20, 9, 1, 13, 15, 23, 1] Best cost: 6492.082 | Path: [1, 9, 15, 14, 17, 20, 1, 11, 4, 22, 10, 12, 1, 8, 18, 3, 19, 1, 13, 23, 21, 2, 1] Best cost: 6459.962 | Path: [1, 18, 8, 10, 4, 12, 1, 11, 13, 20, 19, 17, 1, 22, 2, 21, 14, 9, 1, 3, 23, 15, 1] Best cost: 6411.238 | Path: [1, 3, 19, 17, 14, 1, 11, 13, 20, 15, 2, 1, 8, 18, 10, 22, 1, 4, 12, 21, 23, 9, 1] Best cost: 6343.273 | Path: [1, 8, 18, 10, 4, 12, 1, 11, 13, 20, 3, 1, 22, 2, 19, 17, 14, 1, 9, 15, 21, 23, 1] Best cost: 5917.052 | Path: [1, 9, 15, 14, 17, 20, 1, 11, 13, 3, 19, 1, 8, 18, 10, 22, 1, 4, 12, 2, 21, 23, 1] Generation: #3 Best cost: 5834.152 | Path: [1, 23, 14, 17, 19, 20, 1, 11, 13, 9, 15, 1, 8, 18, 10, 22, 1, 4, 12, 2, 21, 3, 1] OPTIMIZING each tour... Current: [[1, 23, 14, 17, 19, 20, 1], [1, 11, 13, 9, 15, 1], [1, 8, 18, 10, 22, 1], [1, 4, 12, 2, 21, 3, 1]] [1] Cost: 1722.758 to 1656.619 | Optimized: [1, 19, 17, 14, 23, 20, 1] [2] Cost: 1401.293 to 1392.837 | Optimized: [1, 9, 15, 13, 11, 1] [3] Cost: 1132.488 to 1107.833 | Optimized: [1, 22, 10, 8, 18, 1] [4] Cost: 1577.613 to 1568.205 | Optimized: [1, 3, 21, 2, 12, 4, 1] ACO RESULTS [1/295 vol./1656.619 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [2/285 vol./1392.837 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf -> Leipzig Hbf --> Berlin Hbf [3/270 vol./1107.833 km] Berlin Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/300 vol./1568.205 km] Berlin Hbf -> Frankfurt Hbf -> Saarbrücken Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Hannover Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5725.494 km.