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: 16 customers
- Kassel-Wilhelmshöhe (50 vol.)
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (85 vol.)
- Hannover Hbf (40 vol.)
- Stuttgart Hbf (60 vol.)
- Dresden Hbf (30 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (50 vol.)
- Leipzig Hbf (35 vol.)
- Dortmund Hbf (55 vol.)
- Karlsruhe Hbf (60 vol.)
- Köln Hbf (55 vol.)
- Kiel Hbf (80 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (40 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1897.408 km
LOAD: 300 vol.
- Dresden Hbf | 30 vol.
- München Hbf | 80 vol.
- Stuttgart Hbf | 60 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 70 vol.
Tour 2
COST: 1432.072 km
LOAD: 290 vol.
- Hannover Hbf | 40 vol.
- Köln Hbf | 55 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 85 vol.
- Würzburg Hbf | 40 vol.
- Leipzig Hbf | 35 vol.
Tour 3
COST: 1301.685 km
LOAD: 235 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 80 vol.
- Bremen Hbf | 50 vol.
Tour 4
COST: 701.943 km
LOAD: 80 vol.
- Kiel Hbf | 80 vol.
LOAD: 300 vol.
- Dresden Hbf | 30 vol.
- München Hbf | 80 vol.
- Stuttgart Hbf | 60 vol.
- Karlsruhe Hbf | 60 vol.
- Freiburg Hbf | 70 vol.
LOAD: 290 vol.
- Hannover Hbf | 40 vol.
- Köln Hbf | 55 vol.
- Mainz Hbf | 35 vol.
- Frankfurt Hbf | 85 vol.
- Würzburg Hbf | 40 vol.
- Leipzig Hbf | 35 vol.
LOAD: 235 vol.
- Kassel-Wilhelmshöhe | 50 vol.
- Dortmund Hbf | 55 vol.
- Düsseldorf Hbf | 80 vol.
- Bremen Hbf | 50 vol.
LOAD: 80 vol.
- Kiel 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: 905 vol. | Vehicle capacity: 300 vol. Loads: [50, 0, 80, 85, 40, 0, 60, 30, 0, 80, 50, 35, 55, 0, 60, 0, 55, 0, 80, 35, 40, 0, 0, 70] ITERATION Generation: #1 Best cost: 6473.656 | Path: [1, 0, 12, 2, 16, 19, 1, 11, 7, 20, 3, 14, 4, 1, 18, 10, 6, 23, 1, 9, 1] Best cost: 6199.943 | Path: [1, 2, 16, 12, 0, 4, 1, 7, 11, 6, 14, 23, 19, 1, 20, 3, 9, 18, 1, 10, 1] Best cost: 6177.761 | Path: [1, 3, 19, 20, 6, 14, 1, 11, 7, 0, 4, 10, 18, 1, 12, 2, 16, 23, 1, 9, 1] Best cost: 6145.762 | Path: [1, 4, 10, 18, 0, 12, 1, 11, 7, 20, 6, 14, 23, 1, 19, 3, 2, 16, 1, 9, 1] Best cost: 5901.077 | Path: [1, 19, 3, 14, 6, 20, 1, 7, 11, 0, 4, 10, 18, 1, 12, 2, 16, 23, 1, 9, 1] Best cost: 5732.540 | Path: [1, 6, 14, 3, 19, 20, 1, 7, 11, 0, 12, 2, 10, 1, 4, 16, 23, 9, 1, 18, 1] Best cost: 5633.527 | Path: [1, 12, 2, 16, 3, 1, 7, 11, 0, 4, 10, 18, 1, 20, 6, 14, 23, 19, 1, 9, 1] Best cost: 5508.776 | Path: [1, 9, 6, 14, 23, 7, 1, 10, 4, 0, 12, 2, 1, 11, 20, 3, 19, 16, 1, 18, 1] Generation: #5 Best cost: 5334.021 | Path: [1, 9, 6, 14, 23, 7, 1, 11, 20, 3, 19, 16, 4, 1, 0, 12, 2, 10, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 9, 6, 14, 23, 7, 1], [1, 11, 20, 3, 19, 16, 4, 1], [1, 0, 12, 2, 10, 1], [1, 18, 1]] [1] Cost: 1897.477 to 1897.408 | Optimized: [1, 7, 9, 6, 14, 23, 1] [2] Cost: 1432.916 to 1432.072 | Optimized: [1, 4, 16, 19, 3, 20, 11, 1] ACO RESULTS [1/300 vol./1897.408 km] Berlin Hbf -> Dresden Hbf -> München Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [2/290 vol./1432.072 km] Berlin Hbf -> Hannover Hbf -> Köln Hbf -> Mainz Hbf -> Frankfurt Hbf -> Würzburg Hbf -> Leipzig Hbf --> Berlin Hbf [3/235 vol./1301.685 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Bremen Hbf --> Berlin Hbf [4/ 80 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5333.108 km.