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: 17 customers
- Kassel-Wilhelmshöhe (35 vol.)
- Düsseldorf Hbf (25 vol.)
- Frankfurt Hbf (50 vol.)
- Stuttgart Hbf (30 vol.)
- Dresden Hbf (65 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (30 vol.)
- Bremen Hbf (45 vol.)
- Leipzig Hbf (60 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (100 vol.)
- Karlsruhe Hbf (60 vol.)
- Ulm Hbf (50 vol.)
- Mannheim Hbf (80 vol.)
- Mainz Hbf (90 vol.)
- Würzburg Hbf (30 vol.)
- Osnabrück Hbf (80 vol.)
Tour 1
COST: 1136.992 km
LOAD: 290 vol.
- Dortmund Hbf | 65 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 100 vol.
Tour 2
COST: 1564.185 km
LOAD: 275 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Düsseldorf Hbf | 25 vol.
- Mainz Hbf | 90 vol.
- Leipzig Hbf | 60 vol.
- Dresden Hbf | 65 vol.
Tour 3
COST: 1601.147 km
LOAD: 300 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 50 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 60 vol.
- Mannheim Hbf | 80 vol.
- Frankfurt Hbf | 50 vol.
Tour 4
COST: 1024.947 km
LOAD: 130 vol.
- Würzburg Hbf | 30 vol.
- Nürnberg Hbf | 100 vol.
LOAD: 290 vol.
- Dortmund Hbf | 65 vol.
- Osnabrück Hbf | 80 vol.
- Bremen Hbf | 45 vol.
- Hamburg Hbf | 100 vol.
LOAD: 275 vol.
- Kassel-Wilhelmshöhe | 35 vol.
- Düsseldorf Hbf | 25 vol.
- Mainz Hbf | 90 vol.
- Leipzig Hbf | 60 vol.
- Dresden Hbf | 65 vol.
LOAD: 300 vol.
- München Hbf | 30 vol.
- Ulm Hbf | 50 vol.
- Stuttgart Hbf | 30 vol.
- Karlsruhe Hbf | 60 vol.
- Mannheim Hbf | 80 vol.
- Frankfurt Hbf | 50 vol.
LOAD: 130 vol.
- Würzburg Hbf | 30 vol.
- Nürnberg Hbf | 100 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: 995 vol. | Vehicle capacity: 300 vol. Loads: [35, 0, 25, 50, 0, 0, 30, 65, 100, 30, 45, 60, 65, 100, 60, 50, 0, 80, 0, 90, 30, 0, 80, 0] ITERATION Generation: #1 Best cost: 6702.922 | Path: [1, 0, 12, 2, 22, 10, 3, 1, 11, 7, 13, 20, 6, 1, 8, 19, 17, 9, 1, 15, 14, 1] Best cost: 6097.155 | Path: [1, 2, 12, 22, 10, 11, 1, 7, 13, 20, 3, 0, 1, 8, 17, 19, 6, 1, 9, 15, 14, 1] Best cost: 6035.231 | Path: [1, 3, 19, 17, 14, 1, 7, 11, 13, 20, 6, 1, 8, 10, 22, 12, 1, 0, 2, 9, 15, 1] Best cost: 5940.271 | Path: [1, 6, 15, 9, 13, 20, 3, 1, 7, 11, 0, 22, 10, 1, 8, 12, 2, 19, 1, 17, 14, 1] Best cost: 5745.455 | Path: [1, 7, 11, 13, 20, 6, 1, 8, 10, 22, 12, 1, 0, 3, 19, 17, 2, 1, 9, 15, 14, 1] Best cost: 5408.203 | Path: [1, 9, 15, 6, 14, 17, 3, 1, 7, 11, 13, 20, 0, 1, 8, 10, 22, 12, 1, 2, 19, 1] Best cost: 5384.961 | Path: [1, 9, 15, 6, 14, 17, 3, 1, 7, 11, 0, 22, 10, 1, 8, 12, 2, 19, 1, 13, 20, 1] Generation: #2 Best cost: 5374.162 | Path: [1, 8, 10, 22, 12, 1, 7, 11, 0, 2, 19, 1, 3, 17, 14, 6, 15, 9, 1, 13, 20, 1] OPTIMIZING each tour... Current: [[1, 8, 10, 22, 12, 1], [1, 7, 11, 0, 2, 19, 1], [1, 3, 17, 14, 6, 15, 9, 1], [1, 13, 20, 1]] [1] Cost: 1148.907 to 1136.992 | Optimized: [1, 12, 22, 10, 8, 1] [2] Cost: 1592.108 to 1564.185 | Optimized: [1, 0, 2, 19, 11, 7, 1] [3] Cost: 1604.215 to 1601.147 | Optimized: [1, 9, 15, 6, 14, 17, 3, 1] [4] Cost: 1028.932 to 1024.947 | Optimized: [1, 20, 13, 1] ACO RESULTS [1/290 vol./1136.992 km] Berlin Hbf -> Dortmund Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [2/275 vol./1564.185 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Düsseldorf Hbf -> Mainz Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/300 vol./1601.147 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Mannheim Hbf -> Frankfurt Hbf --> Berlin Hbf [4/130 vol./1024.947 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5327.271 km.