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
- Kassel-Wilhelmshöhe (55 vol.)
- Frankfurt Hbf (65 vol.)
- Hannover Hbf (25 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (75 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (55 vol.)
- Bremen Hbf (80 vol.)
- Dortmund Hbf (85 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (65 vol.)
- Ulm Hbf (80 vol.)
- Mannheim Hbf (50 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (45 vol.)
- Saarbrücken Hbf (75 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (60 vol.)
Tour 1
COST: 1446.647 km
LOAD: 300 vol.
- Frankfurt Hbf | 65 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 50 vol.
- Karlsruhe Hbf | 65 vol.
- Stuttgart Hbf | 75 vol.
Tour 2
COST: 1255.116 km
LOAD: 255 vol.
- Dresden Hbf | 70 vol.
- Hannover Hbf | 25 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 55 vol.
- Kiel Hbf | 25 vol.
Tour 3
COST: 1845.66 km
LOAD: 295 vol.
- Saarbrücken Hbf | 75 vol.
- Freiburg Hbf | 60 vol.
- Ulm Hbf | 80 vol.
- Nürnberg Hbf | 80 vol.
Tour 4
COST: 1391.086 km
LOAD: 270 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Dortmund Hbf | 85 vol.
- Aachen Hbf | 80 vol.
- Osnabrück Hbf | 50 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 65 vol.
- Mainz Hbf | 45 vol.
- Mannheim Hbf | 50 vol.
- Karlsruhe Hbf | 65 vol.
- Stuttgart Hbf | 75 vol.
LOAD: 255 vol.
- Dresden Hbf | 70 vol.
- Hannover Hbf | 25 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 55 vol.
- Kiel Hbf | 25 vol.
LOAD: 295 vol.
- Saarbrücken Hbf | 75 vol.
- Freiburg Hbf | 60 vol.
- Ulm Hbf | 80 vol.
- Nürnberg Hbf | 80 vol.
LOAD: 270 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Dortmund Hbf | 85 vol.
- Aachen Hbf | 80 vol.
- Osnabrück 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: 1120 vol. | Vehicle capacity: 300 vol. Loads: [55, 0, 0, 65, 25, 80, 75, 70, 55, 0, 80, 0, 85, 80, 65, 80, 0, 50, 25, 45, 0, 75, 50, 60] ITERATION Generation: #1 Best cost: 6395.896 | Path: [1, 0, 22, 4, 10, 8, 18, 1, 7, 19, 3, 17, 14, 1, 13, 6, 15, 23, 1, 12, 5, 21, 1] Best cost: 6351.037 | Path: [1, 7, 13, 15, 14, 1, 4, 8, 18, 10, 22, 0, 1, 12, 5, 19, 3, 1, 6, 17, 21, 23, 1] Best cost: 6348.819 | Path: [1, 17, 14, 6, 15, 4, 1, 18, 8, 10, 22, 12, 1, 7, 13, 19, 3, 1, 0, 5, 21, 23, 1] Best cost: 6313.117 | Path: [1, 19, 3, 17, 14, 6, 1, 7, 13, 15, 23, 1, 8, 18, 10, 4, 22, 0, 1, 12, 5, 21, 1] Best cost: 6300.110 | Path: [1, 3, 19, 17, 14, 6, 1, 7, 13, 15, 23, 1, 8, 18, 10, 22, 4, 0, 1, 12, 5, 21, 1] Best cost: 6293.138 | Path: [1, 7, 0, 12, 22, 4, 1, 8, 18, 10, 5, 19, 1, 13, 14, 17, 3, 1, 15, 6, 23, 21, 1] Best cost: 6242.142 | Path: [1, 18, 8, 10, 22, 0, 4, 1, 7, 13, 17, 14, 1, 12, 5, 19, 3, 1, 6, 15, 23, 21, 1] Best cost: 6189.665 | Path: [1, 23, 14, 6, 15, 1, 4, 8, 18, 10, 22, 0, 1, 7, 13, 3, 19, 1, 12, 5, 21, 17, 1] Best cost: 6153.458 | Path: [1, 19, 3, 17, 14, 6, 1, 7, 4, 10, 8, 18, 1, 0, 12, 22, 5, 1, 13, 15, 23, 21, 1] Best cost: 6045.062 | Path: [1, 3, 19, 17, 14, 6, 1, 7, 4, 10, 8, 18, 1, 13, 15, 21, 23, 1, 22, 12, 5, 0, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 17, 14, 6, 1], [1, 7, 4, 10, 8, 18, 1], [1, 13, 15, 21, 23, 1], [1, 22, 12, 5, 0, 1]] [3] Cost: 1946.894 to 1845.660 | Optimized: [1, 21, 23, 15, 13, 1] [4] Cost: 1396.405 to 1391.086 | Optimized: [1, 0, 12, 5, 22, 1] ACO RESULTS [1/300 vol./1446.647 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf --> Berlin Hbf [2/255 vol./1255.116 km] Berlin Hbf -> Dresden Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/295 vol./1845.660 km] Berlin Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Ulm Hbf -> Nürnberg Hbf --> Berlin Hbf [4/270 vol./1391.086 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Aachen Hbf -> Osnabrück Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5938.509 km.