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 (55 vol.)
- Düsseldorf Hbf (55 vol.)
- Frankfurt Hbf (95 vol.)
- Hannover Hbf (95 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (60 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (65 vol.)
- Dortmund Hbf (60 vol.)
- Nürnberg Hbf (100 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (60 vol.)
- Mainz Hbf (25 vol.)
- Würzburg Hbf (90 vol.)
- Saarbrücken Hbf (35 vol.)
- Freiburg Hbf (30 vol.)
Tour 1
COST: 1364.394 km
LOAD: 290 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 55 vol.
- Köln Hbf | 55 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 95 vol.
Tour 2
COST: 1187.501 km
LOAD: 290 vol.
- Würzburg Hbf | 90 vol.
- Nürnberg Hbf | 100 vol.
- Leipzig Hbf | 65 vol.
- Dresden Hbf | 35 vol.
Tour 3
COST: 1096.949 km
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Hannover Hbf | 95 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 40 vol.
Tour 4
COST: 1957.058 km
LOAD: 185 vol.
- München Hbf | 60 vol.
- Freiburg Hbf | 30 vol.
- Saarbrücken Hbf | 35 vol.
- Mannheim Hbf | 60 vol.
LOAD: 290 vol.
- Dortmund Hbf | 60 vol.
- Düsseldorf Hbf | 55 vol.
- Köln Hbf | 55 vol.
- Mainz Hbf | 25 vol.
- Frankfurt Hbf | 95 vol.
LOAD: 290 vol.
- Würzburg Hbf | 90 vol.
- Nürnberg Hbf | 100 vol.
- Leipzig Hbf | 65 vol.
- Dresden Hbf | 35 vol.
LOAD: 285 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Hannover Hbf | 95 vol.
- Bremen Hbf | 95 vol.
- Hamburg Hbf | 40 vol.
LOAD: 185 vol.
- München Hbf | 60 vol.
- Freiburg Hbf | 30 vol.
- Saarbrücken Hbf | 35 vol.
- Mannheim Hbf | 60 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: 1050 vol. | Vehicle capacity: 300 vol. Loads: [55, 0, 55, 95, 95, 0, 0, 35, 40, 60, 95, 65, 60, 100, 0, 0, 55, 60, 0, 25, 90, 35, 0, 30] ITERATION Generation: #1 Best cost: 6618.679 | Path: [1, 0, 20, 3, 19, 21, 1, 7, 11, 12, 2, 16, 23, 1, 4, 10, 8, 17, 1, 13, 9, 1] Best cost: 6346.205 | Path: [1, 2, 16, 12, 0, 11, 1, 7, 13, 20, 19, 21, 1, 8, 10, 4, 17, 1, 3, 23, 9, 1] Best cost: 6153.947 | Path: [1, 3, 19, 17, 20, 23, 1, 7, 11, 13, 9, 21, 1, 8, 10, 4, 0, 1, 12, 2, 16, 1] Best cost: 6141.426 | Path: [1, 4, 8, 10, 12, 1, 0, 3, 19, 17, 21, 23, 1, 7, 11, 13, 20, 1, 16, 2, 9, 1] Best cost: 5689.694 | Path: [1, 8, 10, 4, 0, 1, 11, 7, 20, 13, 1, 12, 2, 16, 3, 19, 1, 17, 21, 23, 9, 1] Best cost: 5620.287 | Path: [1, 7, 11, 13, 20, 1, 8, 10, 4, 0, 1, 12, 2, 16, 19, 3, 1, 17, 21, 23, 9, 1] Generation: #2 Best cost: 5608.528 | Path: [1, 12, 2, 16, 19, 3, 1, 7, 11, 13, 20, 1, 8, 10, 4, 0, 1, 9, 23, 21, 17, 1] OPTIMIZING each tour... Current: [[1, 12, 2, 16, 19, 3, 1], [1, 7, 11, 13, 20, 1], [1, 8, 10, 4, 0, 1], [1, 9, 23, 21, 17, 1]] [2] Cost: 1190.097 to 1187.501 | Optimized: [1, 20, 13, 11, 7, 1] [3] Cost: 1096.979 to 1096.949 | Optimized: [1, 0, 4, 10, 8, 1] ACO RESULTS [1/290 vol./1364.394 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/290 vol./1187.501 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/285 vol./1096.949 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [4/185 vol./1957.058 km] Berlin Hbf -> München Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mannheim Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5605.902 km.