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: 400 vol.
ACTIVE: 15 customers
- Berlin Hbf (100 vol.)
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (25 vol.)
- Aachen Hbf (50 vol.)
- Hamburg Hbf (75 vol.)
- Leipzig Hbf (95 vol.)
- Dortmund Hbf (40 vol.)
- Nürnberg Hbf (85 vol.)
- Ulm Hbf (80 vol.)
- Mannheim Hbf (85 vol.)
- Kiel Hbf (55 vol.)
- Würzburg Hbf (35 vol.)
- Saarbrücken Hbf (80 vol.)
- Osnabrück Hbf (90 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1528.107 km
LOAD: 380 vol.
- Osnabrück Hbf | 90 vol.
- Dortmund Hbf | 40 vol.
- Düsseldorf Hbf | 35 vol.
- Aachen Hbf | 50 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 25 vol.
- Frankfurt Hbf | 25 vol.
- Würzburg Hbf | 35 vol.
Tour 2
COST: 1230.172 km
LOAD: 325 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 55 vol.
- Berlin Hbf | 100 vol.
- Leipzig Hbf | 95 vol.
Tour 3
COST: 1002.717 km
LOAD: 250 vol.
- Mannheim Hbf | 85 vol.
- Ulm Hbf | 80 vol.
- Nürnberg Hbf | 85 vol.
LOAD: 380 vol.
- Osnabrück Hbf | 90 vol.
- Dortmund Hbf | 40 vol.
- Düsseldorf Hbf | 35 vol.
- Aachen Hbf | 50 vol.
- Saarbrücken Hbf | 80 vol.
- Freiburg Hbf | 25 vol.
- Frankfurt Hbf | 25 vol.
- Würzburg Hbf | 35 vol.
LOAD: 325 vol.
- Hamburg Hbf | 75 vol.
- Kiel Hbf | 55 vol.
- Berlin Hbf | 100 vol.
- Leipzig Hbf | 95 vol.
LOAD: 250 vol.
- Mannheim Hbf | 85 vol.
- Ulm Hbf | 80 vol.
- Nürnberg Hbf | 85 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 955 vol. | Vehicle capacity: 400 vol. Loads: [0, 100, 35, 25, 0, 50, 0, 0, 75, 0, 0, 95, 40, 85, 0, 80, 0, 85, 55, 0, 35, 80, 90, 25] ITERATION Generation: #1 Best cost: 4880.733 | Path: [0, 1, 11, 13, 20, 3, 23, 2, 0, 12, 22, 8, 18, 5, 17, 0, 21, 15, 0] Best cost: 4363.177 | Path: [0, 2, 12, 22, 8, 18, 1, 0, 3, 17, 23, 21, 5, 20, 13, 0, 11, 15, 0] Best cost: 4324.557 | Path: [0, 5, 2, 12, 22, 8, 18, 3, 23, 0, 20, 13, 15, 17, 21, 0, 11, 1, 0] Best cost: 3987.904 | Path: [0, 8, 18, 1, 11, 20, 3, 0, 22, 12, 2, 5, 21, 17, 0, 13, 15, 23, 0] Best cost: 3974.520 | Path: [0, 22, 12, 2, 5, 3, 17, 23, 20, 0, 11, 1, 8, 18, 0, 21, 15, 13, 0] Best cost: 3872.404 | Path: [0, 8, 18, 22, 12, 2, 5, 20, 0, 3, 17, 21, 23, 15, 13, 0, 11, 1, 0] Generation: #10 Best cost: 3830.106 | Path: [0, 22, 12, 2, 5, 21, 23, 20, 3, 0, 11, 1, 8, 18, 0, 17, 15, 13, 0] OPTIMIZING each tour... Current: [[0, 22, 12, 2, 5, 21, 23, 20, 3, 0], [0, 11, 1, 8, 18, 0], [0, 17, 15, 13, 0]] [1] Cost: 1563.978 to 1528.107 | Optimized: [0, 22, 12, 2, 5, 21, 23, 3, 20, 0] [2] Cost: 1263.411 to 1230.172 | Optimized: [0, 8, 18, 1, 11, 0] ACO RESULTS [1/380 vol./1528.107 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Frankfurt Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [2/325 vol./1230.172 km] Kassel-Wilhelmshöhe -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Leipzig Hbf --> Kassel-Wilhelmshöhe [3/250 vol./1002.717 km] Kassel-Wilhelmshöhe -> Mannheim Hbf -> Ulm Hbf -> Nürnberg Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3760.996 km.