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 (90 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (55 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (35 vol.)
- München Hbf (30 vol.)
- Bremen Hbf (35 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (65 vol.)
- Nürnberg Hbf (80 vol.)
- Köln Hbf (90 vol.)
- Mannheim Hbf (75 vol.)
- Kiel Hbf (100 vol.)
- Mainz Hbf (55 vol.)
- Saarbrücken Hbf (25 vol.)
- Freiburg Hbf (95 vol.)
Tour 1
COST: 2003.272 km
LOAD: 280 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 75 vol.
- Saarbrücken Hbf | 25 vol.
- Freiburg Hbf | 95 vol.
- München Hbf | 30 vol.
Tour 2
COST: 1346.567 km
LOAD: 270 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 50 vol.
- Nürnberg Hbf | 80 vol.
- Hannover Hbf | 45 vol.
Tour 3
COST: 1357.52 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Köln Hbf | 90 vol.
- Aachen Hbf | 55 vol.
- Dortmund Hbf | 65 vol.
Tour 4
COST: 959.498 km
LOAD: 170 vol.
- Hamburg Hbf | 35 vol.
- Bremen Hbf | 35 vol.
- Kiel Hbf | 100 vol.
LOAD: 280 vol.
- Mainz Hbf | 55 vol.
- Mannheim Hbf | 75 vol.
- Saarbrücken Hbf | 25 vol.
- Freiburg Hbf | 95 vol.
- München Hbf | 30 vol.
LOAD: 270 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 50 vol.
- Nürnberg Hbf | 80 vol.
- Hannover Hbf | 45 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Köln Hbf | 90 vol.
- Aachen Hbf | 55 vol.
- Dortmund Hbf | 65 vol.
LOAD: 170 vol.
- Hamburg Hbf | 35 vol.
- Bremen Hbf | 35 vol.
- Kiel 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: 1020 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 0, 0, 45, 55, 0, 95, 35, 30, 35, 50, 65, 80, 0, 0, 90, 75, 100, 55, 0, 25, 0, 95] ITERATION Generation: #1 Best cost: 6568.448 | Path: [1, 0, 12, 16, 5, 1, 11, 7, 13, 9, 21, 1, 18, 8, 10, 4, 19, 1, 17, 23, 1] Best cost: 6406.091 | Path: [1, 12, 16, 5, 19, 21, 1, 11, 7, 13, 9, 4, 1, 8, 18, 10, 0, 1, 17, 23, 1] Best cost: 6338.960 | Path: [1, 23, 17, 19, 21, 9, 1, 7, 11, 4, 10, 8, 1, 18, 0, 12, 1, 13, 16, 5, 1] Best cost: 6151.788 | Path: [1, 17, 19, 21, 23, 9, 1, 7, 11, 4, 10, 8, 1, 18, 0, 12, 1, 13, 5, 16, 1] Best cost: 6151.696 | Path: [1, 17, 19, 21, 23, 9, 1, 11, 7, 4, 10, 8, 1, 0, 12, 16, 5, 1, 18, 13, 1] Best cost: 6146.440 | Path: [1, 17, 19, 21, 23, 9, 1, 11, 7, 4, 10, 8, 1, 12, 5, 16, 0, 1, 18, 13, 1] Best cost: 5761.823 | Path: [1, 17, 19, 21, 23, 9, 1, 11, 7, 13, 4, 1, 0, 12, 16, 5, 1, 10, 8, 18, 1] Generation: #3 Best cost: 5711.826 | Path: [1, 19, 17, 21, 23, 9, 1, 11, 7, 13, 4, 1, 0, 12, 16, 5, 1, 8, 18, 10, 1] OPTIMIZING each tour... Current: [[1, 19, 17, 21, 23, 9, 1], [1, 11, 7, 13, 4, 1], [1, 0, 12, 16, 5, 1], [1, 8, 18, 10, 1]] [2] Cost: 1372.789 to 1346.567 | Optimized: [1, 7, 11, 13, 4, 1] [3] Cost: 1360.700 to 1357.520 | Optimized: [1, 0, 16, 5, 12, 1] [4] Cost: 975.065 to 959.498 | Optimized: [1, 8, 10, 18, 1] ACO RESULTS [1/280 vol./2003.272 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> München Hbf --> Berlin Hbf [2/270 vol./1346.567 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Nürnberg Hbf -> Hannover Hbf --> Berlin Hbf [3/300 vol./1357.520 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Köln Hbf -> Aachen Hbf -> Dortmund Hbf --> Berlin Hbf [4/170 vol./ 959.498 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5666.857 km.