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
- Frankfurt Hbf (65 vol.)
- Hannover Hbf (20 vol.)
- Aachen Hbf (45 vol.)
- Stuttgart Hbf (45 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (45 vol.)
- München Hbf (20 vol.)
- Bremen Hbf (30 vol.)
- Leipzig Hbf (30 vol.)
- Dortmund Hbf (80 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (85 vol.)
- Köln Hbf (100 vol.)
- Mannheim Hbf (55 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (70 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1589.414 km
LOAD: 300 vol.
- München Hbf | 20 vol.
- Ulm Hbf | 85 vol.
- Stuttgart Hbf | 45 vol.
- Karlsruhe Hbf | 95 vol.
- Mannheim Hbf | 55 vol.
Tour 2
COST: 1239.854 km
LOAD: 280 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 30 vol.
- Hannover Hbf | 20 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 30 vol.
- Hamburg Hbf | 45 vol.
Tour 3
COST: 1745.727 km
LOAD: 280 vol.
- Frankfurt Hbf | 65 vol.
- Mainz Hbf | 100 vol.
- Saarbrücken Hbf | 30 vol.
- Freiburg Hbf | 35 vol.
- Würzburg Hbf | 50 vol.
Tour 4
COST: 1296.752 km
LOAD: 225 vol.
- Köln Hbf | 100 vol.
- Aachen Hbf | 45 vol.
- Dortmund Hbf | 80 vol.
LOAD: 300 vol.
- München Hbf | 20 vol.
- Ulm Hbf | 85 vol.
- Stuttgart Hbf | 45 vol.
- Karlsruhe Hbf | 95 vol.
- Mannheim Hbf | 55 vol.
LOAD: 280 vol.
- Dresden Hbf | 85 vol.
- Leipzig Hbf | 30 vol.
- Hannover Hbf | 20 vol.
- Osnabrück Hbf | 70 vol.
- Bremen Hbf | 30 vol.
- Hamburg Hbf | 45 vol.
LOAD: 280 vol.
- Frankfurt Hbf | 65 vol.
- Mainz Hbf | 100 vol.
- Saarbrücken Hbf | 30 vol.
- Freiburg Hbf | 35 vol.
- Würzburg Hbf | 50 vol.
LOAD: 225 vol.
- Köln Hbf | 100 vol.
- Aachen Hbf | 45 vol.
- Dortmund 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: 1085 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 0, 65, 20, 45, 45, 85, 45, 20, 30, 30, 80, 0, 95, 85, 100, 55, 0, 100, 50, 30, 70, 35] ITERATION Generation: #1 Best cost: 6978.633 | Path: [1, 3, 19, 17, 21, 23, 1, 11, 7, 4, 10, 8, 22, 9, 1, 20, 6, 14, 15, 1, 12, 16, 5, 1] Best cost: 6615.752 | Path: [1, 9, 15, 6, 14, 17, 1, 11, 7, 12, 16, 1, 8, 10, 4, 22, 5, 3, 1, 20, 19, 21, 23, 1] Best cost: 6521.118 | Path: [1, 11, 7, 4, 22, 12, 1, 8, 10, 16, 5, 21, 23, 1, 15, 6, 14, 17, 9, 1, 20, 3, 19, 1] Best cost: 6463.006 | Path: [1, 8, 10, 4, 22, 12, 5, 1, 11, 7, 20, 3, 17, 1, 9, 15, 6, 14, 23, 1, 19, 21, 16, 1] Best cost: 6121.369 | Path: [1, 9, 15, 6, 14, 17, 1, 11, 7, 4, 10, 22, 8, 1, 20, 3, 19, 21, 23, 1, 12, 16, 5, 1] Best cost: 6084.747 | Path: [1, 17, 14, 6, 15, 9, 1, 7, 11, 4, 10, 22, 8, 1, 12, 16, 5, 21, 23, 1, 3, 19, 20, 1] Best cost: 6030.253 | Path: [1, 9, 15, 6, 14, 17, 1, 11, 7, 4, 22, 10, 8, 1, 20, 3, 19, 21, 23, 1, 5, 16, 12, 1] Generation: #2 Best cost: 6021.841 | Path: [1, 9, 15, 6, 14, 17, 1, 7, 11, 4, 10, 22, 8, 1, 20, 3, 19, 21, 23, 1, 16, 5, 12, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 14, 17, 1], [1, 7, 11, 4, 10, 22, 8, 1], [1, 20, 3, 19, 21, 23, 1], [1, 16, 5, 12, 1]] [2] Cost: 1333.370 to 1239.854 | Optimized: [1, 7, 11, 4, 22, 10, 8, 1] [3] Cost: 1802.305 to 1745.727 | Optimized: [1, 3, 19, 21, 23, 20, 1] ACO RESULTS [1/300 vol./1589.414 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf --> Berlin Hbf [2/280 vol./1239.854 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/280 vol./1745.727 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [4/225 vol./1296.752 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Dortmund Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5871.747 km.