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 (75 vol.)
- Düsseldorf Hbf (25 vol.)
- Frankfurt Hbf (30 vol.)
- Hannover Hbf (65 vol.)
- Dresden Hbf (55 vol.)
- Hamburg Hbf (65 vol.)
- Bremen Hbf (85 vol.)
- Leipzig Hbf (40 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (30 vol.)
- Köln Hbf (100 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (85 vol.)
- Würzburg Hbf (25 vol.)
- Saarbrücken Hbf (30 vol.)
- Freiburg Hbf (35 vol.)
Tour 1
COST: 1846.527 km
LOAD: 295 vol.
- Leipzig Hbf | 40 vol.
- Würzburg Hbf | 25 vol.
- Frankfurt Hbf | 30 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 30 vol.
- Mainz Hbf | 85 vol.
Tour 2
COST: 1096.949 km
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Hannover Hbf | 65 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 65 vol.
Tour 3
COST: 1514.141 km
LOAD: 260 vol.
- Düsseldorf Hbf | 25 vol.
- Köln Hbf | 100 vol.
- Nürnberg Hbf | 80 vol.
- Dresden Hbf | 55 vol.
Tour 4
COST: 701.943 km
LOAD: 90 vol.
- Kiel Hbf | 90 vol.
LOAD: 295 vol.
- Leipzig Hbf | 40 vol.
- Würzburg Hbf | 25 vol.
- Frankfurt Hbf | 30 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 35 vol.
- Saarbrücken Hbf | 30 vol.
- Mainz Hbf | 85 vol.
LOAD: 290 vol.
- Kassel-Wilhelmshöhe | 75 vol.
- Hannover Hbf | 65 vol.
- Bremen Hbf | 85 vol.
- Hamburg Hbf | 65 vol.
LOAD: 260 vol.
- Düsseldorf Hbf | 25 vol.
- Köln Hbf | 100 vol.
- Nürnberg Hbf | 80 vol.
- Dresden Hbf | 55 vol.
LOAD: 90 vol.
- Kiel Hbf | 90 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: 935 vol. | Vehicle capacity: 300 vol. Loads: [75, 0, 25, 30, 65, 0, 0, 55, 65, 0, 85, 40, 0, 80, 30, 0, 100, 20, 90, 85, 25, 30, 0, 35] ITERATION Generation: #1 Best cost: 7042.998 | Path: [1, 0, 20, 13, 3, 19, 1, 11, 7, 4, 10, 2, 17, 1, 8, 18, 16, 21, 1, 14, 23, 1] Best cost: 5882.981 | Path: [1, 2, 16, 19, 3, 17, 14, 1, 7, 11, 0, 20, 13, 1, 4, 10, 8, 21, 23, 1, 18, 1] Best cost: 5857.883 | Path: [1, 7, 11, 0, 4, 8, 1, 18, 16, 2, 19, 1, 10, 3, 17, 14, 23, 21, 20, 1, 13, 1] Best cost: 5534.642 | Path: [1, 20, 3, 19, 17, 14, 23, 21, 2, 1, 11, 7, 13, 0, 1, 4, 10, 8, 1, 18, 16, 1] Best cost: 5391.817 | Path: [1, 20, 3, 19, 17, 14, 23, 21, 2, 1, 7, 11, 13, 0, 1, 8, 18, 10, 1, 4, 16, 1] Best cost: 5222.831 | Path: [1, 17, 14, 23, 21, 19, 3, 20, 11, 1, 8, 10, 4, 0, 1, 7, 13, 2, 16, 1, 18, 1] OPTIMIZING each tour... Current: [[1, 17, 14, 23, 21, 19, 3, 20, 11, 1], [1, 8, 10, 4, 0, 1], [1, 7, 13, 2, 16, 1], [1, 18, 1]] [1] Cost: 1852.072 to 1846.527 | Optimized: [1, 11, 20, 3, 17, 14, 23, 21, 19, 1] [2] Cost: 1096.979 to 1096.949 | Optimized: [1, 0, 4, 10, 8, 1] [3] Cost: 1571.837 to 1514.141 | Optimized: [1, 2, 16, 13, 7, 1] ACO RESULTS [1/295 vol./1846.527 km] Berlin Hbf -> Leipzig Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf --> Berlin Hbf [2/290 vol./1096.949 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/260 vol./1514.141 km] Berlin Hbf -> Düsseldorf Hbf -> Köln Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [4/ 90 vol./ 701.943 km] Berlin Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5159.560 km.