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
- Kassel-Wilhelmshöhe (65 vol.)
- Düsseldorf Hbf (30 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (75 vol.)
- Stuttgart Hbf (80 vol.)
- Dresden Hbf (45 vol.)
- Hamburg Hbf (40 vol.)
- Bremen Hbf (55 vol.)
- Leipzig Hbf (70 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (75 vol.)
- Köln Hbf (25 vol.)
- Mannheim Hbf (90 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (35 vol.)
- Würzburg Hbf (70 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (85 vol.)
- Freiburg Hbf (40 vol.)
Tour 1
COST: 1435.977 km
LOAD: 270 vol.
- Aachen Hbf | 75 vol.
- Köln Hbf | 25 vol.
- Düsseldorf Hbf | 30 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 55 vol.
Tour 2
COST: 1174.141 km
LOAD: 285 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 70 vol.
- Hannover Hbf | 65 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 65 vol.
Tour 3
COST: 1466.746 km
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Würzburg Hbf | 70 vol.
- Stuttgart Hbf | 80 vol.
- Ulm Hbf | 75 vol.
Tour 4
COST: 1749.349 km
LOAD: 255 vol.
- Mannheim Hbf | 90 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 40 vol.
- Saarbrücken Hbf | 50 vol.
- Mainz Hbf | 35 vol.
LOAD: 270 vol.
- Aachen Hbf | 75 vol.
- Köln Hbf | 25 vol.
- Düsseldorf Hbf | 30 vol.
- Osnabrück Hbf | 85 vol.
- Bremen Hbf | 55 vol.
LOAD: 285 vol.
- Dresden Hbf | 45 vol.
- Leipzig Hbf | 70 vol.
- Hannover Hbf | 65 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 65 vol.
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 65 vol.
- Würzburg Hbf | 70 vol.
- Stuttgart Hbf | 80 vol.
- Ulm Hbf | 75 vol.
LOAD: 255 vol.
- Mannheim Hbf | 90 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 40 vol.
- Saarbrücken Hbf | 50 vol.
- Mainz Hbf | 35 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: 1100 vol. | Vehicle capacity: 300 vol. Loads: [65, 0, 30, 0, 65, 75, 80, 45, 40, 0, 55, 70, 0, 0, 40, 75, 25, 90, 65, 35, 70, 50, 85, 40] ITERATION Generation: #1 Best cost: 7236.016 | Path: [1, 0, 22, 10, 4, 2, 1, 11, 7, 19, 17, 14, 1, 8, 18, 20, 6, 23, 1, 15, 21, 5, 16, 1] Best cost: 6987.723 | Path: [1, 2, 16, 5, 17, 14, 19, 1, 8, 18, 10, 22, 21, 1, 7, 11, 4, 0, 23, 1, 20, 6, 15, 1] Best cost: 6158.481 | Path: [1, 5, 16, 2, 22, 10, 1, 11, 7, 4, 8, 18, 1, 0, 19, 17, 14, 23, 1, 20, 6, 15, 21, 1] Best cost: 6127.555 | Path: [1, 20, 15, 6, 14, 19, 1, 7, 11, 0, 22, 16, 1, 2, 5, 21, 17, 23, 1, 8, 18, 10, 4, 1] Best cost: 6106.846 | Path: [1, 7, 11, 4, 8, 18, 1, 10, 22, 2, 16, 5, 1, 0, 20, 6, 14, 23, 1, 19, 17, 21, 15, 1] Best cost: 6054.200 | Path: [1, 5, 16, 2, 22, 10, 1, 7, 11, 4, 8, 18, 1, 0, 19, 17, 14, 21, 1, 20, 6, 15, 23, 1] Generation: #3 Best cost: 5985.848 | Path: [1, 5, 16, 2, 22, 10, 1, 11, 7, 4, 8, 18, 1, 20, 6, 14, 17, 1, 0, 19, 21, 23, 15, 1] Generation: #4 Best cost: 5862.955 | Path: [1, 5, 16, 2, 22, 10, 1, 7, 11, 4, 8, 18, 1, 0, 20, 6, 15, 1, 19, 17, 14, 23, 21, 1] OPTIMIZING each tour... Current: [[1, 5, 16, 2, 22, 10, 1], [1, 7, 11, 4, 8, 18, 1], [1, 0, 20, 6, 15, 1], [1, 19, 17, 14, 23, 21, 1]] [4] Cost: 1786.091 to 1749.349 | Optimized: [1, 17, 14, 23, 21, 19, 1] ACO RESULTS [1/270 vol./1435.977 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Bremen Hbf --> Berlin Hbf [2/285 vol./1174.141 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/290 vol./1466.746 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Würzburg Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [4/255 vol./1749.349 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5826.213 km.