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: 20 customers
- Kassel-Wilhelmshöhe (30 vol.)
- Düsseldorf Hbf (70 vol.)
- Hannover Hbf (100 vol.)
- Aachen Hbf (55 vol.)
- Stuttgart Hbf (45 vol.)
- Dresden Hbf (25 vol.)
- Hamburg Hbf (90 vol.)
- München Hbf (70 vol.)
- Bremen Hbf (100 vol.)
- Leipzig Hbf (90 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (85 vol.)
- Karlsruhe Hbf (40 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (50 vol.)
- Mannheim Hbf (30 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (100 vol.)
- Freiburg Hbf (40 vol.)
Tour 1
COST: 1187.501 km
LOAD: 300 vol.
- Würzburg Hbf | 100 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 90 vol.
- Dresden Hbf | 25 vol.
Tour 2
COST: 805.867 km
LOAD: 290 vol.
- Hannover Hbf | 100 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 90 vol.
Tour 3
COST: 1863.045 km
LOAD: 295 vol.
- Kiel Hbf | 90 vol.
- Düsseldorf Hbf | 70 vol.
- Köln Hbf | 50 vol.
- Aachen Hbf | 55 vol.
- Mannheim Hbf | 30 vol.
Tour 4
COST: 1877.634 km
LOAD: 290 vol.
- München Hbf | 70 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 45 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 40 vol.
- Mainz Hbf | 75 vol.
Tour 5
COST: 1044.694 km
LOAD: 120 vol.
- Dortmund Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 30 vol.
LOAD: 300 vol.
- Würzburg Hbf | 100 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 90 vol.
- Dresden Hbf | 25 vol.
LOAD: 290 vol.
- Hannover Hbf | 100 vol.
- Bremen Hbf | 100 vol.
- Hamburg Hbf | 90 vol.
LOAD: 295 vol.
- Kiel Hbf | 90 vol.
- Düsseldorf Hbf | 70 vol.
- Köln Hbf | 50 vol.
- Aachen Hbf | 55 vol.
- Mannheim Hbf | 30 vol.
LOAD: 290 vol.
- München Hbf | 70 vol.
- Ulm Hbf | 20 vol.
- Stuttgart Hbf | 45 vol.
- Karlsruhe Hbf | 40 vol.
- Freiburg Hbf | 40 vol.
- Mainz Hbf | 75 vol.
LOAD: 120 vol.
- Dortmund Hbf | 90 vol.
- Kassel-Wilhelmshöhe | 30 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: 1295 vol. | Vehicle capacity: 300 vol. Loads: [30, 0, 70, 0, 100, 55, 45, 25, 90, 70, 100, 90, 90, 85, 40, 20, 50, 30, 90, 75, 100, 0, 0, 40] ITERATION Generation: #1 Best cost: 7892.186 | Path: [1, 0, 12, 2, 16, 5, 1, 11, 7, 13, 20, 1, 8, 18, 10, 15, 1, 4, 17, 14, 6, 19, 1, 9, 23, 1] Best cost: 7737.238 | Path: [1, 2, 16, 5, 19, 17, 15, 1, 7, 11, 4, 0, 14, 1, 8, 18, 10, 1, 12, 20, 13, 1, 9, 6, 23, 1] Best cost: 7317.842 | Path: [1, 4, 10, 8, 1, 11, 7, 13, 20, 1, 0, 12, 2, 16, 5, 1, 18, 23, 14, 6, 15, 17, 1, 9, 19, 1] Best cost: 7009.882 | Path: [1, 5, 16, 2, 12, 0, 1, 7, 11, 20, 13, 1, 4, 10, 8, 1, 18, 17, 14, 6, 15, 9, 1, 19, 23, 1] Best cost: 6857.128 | Path: [1, 9, 15, 6, 14, 17, 19, 1, 7, 11, 13, 20, 1, 8, 18, 10, 1, 0, 12, 2, 16, 5, 1, 4, 23, 1] Generation: #6 Best cost: 6807.748 | Path: [1, 11, 7, 13, 20, 1, 4, 10, 8, 1, 18, 2, 16, 5, 17, 1, 9, 15, 6, 14, 23, 19, 1, 0, 12, 1] OPTIMIZING each tour... Current: [[1, 11, 7, 13, 20, 1], [1, 4, 10, 8, 1], [1, 18, 2, 16, 5, 17, 1], [1, 9, 15, 6, 14, 23, 19, 1], [1, 0, 12, 1]] [1] Cost: 1216.319 to 1187.501 | Optimized: [1, 20, 13, 11, 7, 1] [5] Cost: 1044.883 to 1044.694 | Optimized: [1, 12, 0, 1] ACO RESULTS [1/300 vol./1187.501 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [2/290 vol./ 805.867 km] Berlin Hbf -> Hannover Hbf -> Bremen Hbf -> Hamburg Hbf --> Berlin Hbf [3/295 vol./1863.045 km] Berlin Hbf -> Kiel Hbf -> Düsseldorf Hbf -> Köln Hbf -> Aachen Hbf -> Mannheim Hbf --> Berlin Hbf [4/290 vol./1877.634 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Mainz Hbf --> Berlin Hbf [5/120 vol./1044.694 km] Berlin Hbf -> Dortmund Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 6778.741 km.