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.)
- Düsseldorf Hbf (50 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (65 vol.)
- Dresden Hbf (30 vol.)
- München Hbf (50 vol.)
- Bremen Hbf (45 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (85 vol.)
- Ulm Hbf (100 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (50 vol.)
- Saarbrücken Hbf (50 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1566.86 km
LOAD: 295 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 100 vol.
- Karlsruhe Hbf | 85 vol.
- Nürnberg Hbf | 60 vol.
Tour 2
COST: 1427.23 km
LOAD: 260 vol.
- Kiel Hbf | 50 vol.
- Bremen Hbf | 45 vol.
- Hannover Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Dresden Hbf | 30 vol.
Tour 3
COST: 1782.98 km
LOAD: 270 vol.
- Mainz Hbf | 50 vol.
- Mannheim Hbf | 100 vol.
- Freiburg Hbf | 70 vol.
- Saarbrücken Hbf | 50 vol.
Tour 4
COST: 1272.297 km
LOAD: 205 vol.
- Dortmund Hbf | 90 vol.
- Düsseldorf Hbf | 50 vol.
- Aachen Hbf | 65 vol.
LOAD: 295 vol.
- München Hbf | 50 vol.
- Ulm Hbf | 100 vol.
- Karlsruhe Hbf | 85 vol.
- Nürnberg Hbf | 60 vol.
LOAD: 260 vol.
- Kiel Hbf | 50 vol.
- Bremen Hbf | 45 vol.
- Hannover Hbf | 45 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Dresden Hbf | 30 vol.
LOAD: 270 vol.
- Mainz Hbf | 50 vol.
- Mannheim Hbf | 100 vol.
- Freiburg Hbf | 70 vol.
- Saarbrücken Hbf | 50 vol.
LOAD: 205 vol.
- Dortmund Hbf | 90 vol.
- Düsseldorf Hbf | 50 vol.
- Aachen Hbf | 65 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: 1030 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 50, 0, 45, 65, 0, 30, 0, 50, 45, 0, 90, 60, 85, 100, 0, 100, 50, 50, 0, 50, 0, 70] ITERATION Generation: #1 Best cost: 6735.781 | Path: [1, 0, 12, 2, 5, 1, 7, 13, 15, 14, 1, 4, 10, 18, 19, 17, 1, 9, 23, 21, 1] Best cost: 6677.506 | Path: [1, 10, 4, 0, 12, 7, 1, 13, 9, 15, 14, 1, 18, 2, 5, 21, 19, 1, 23, 17, 1] Best cost: 6510.974 | Path: [1, 15, 9, 13, 14, 1, 7, 0, 4, 10, 18, 1, 12, 2, 5, 19, 1, 17, 21, 23, 1] Best cost: 6470.399 | Path: [1, 17, 14, 23, 4, 1, 7, 13, 9, 15, 19, 1, 18, 10, 12, 2, 5, 1, 0, 21, 1] Best cost: 6333.647 | Path: [1, 23, 14, 17, 4, 1, 7, 13, 9, 15, 21, 1, 18, 10, 12, 2, 5, 1, 0, 19, 1] Best cost: 6121.516 | Path: [1, 21, 14, 17, 19, 1, 7, 0, 4, 10, 18, 1, 13, 9, 15, 23, 1, 12, 2, 5, 1] Best cost: 6079.635 | Path: [1, 13, 9, 15, 14, 1, 7, 0, 4, 10, 18, 1, 19, 17, 21, 23, 1, 5, 2, 12, 1] OPTIMIZING each tour... Current: [[1, 13, 9, 15, 14, 1], [1, 7, 0, 4, 10, 18, 1], [1, 19, 17, 21, 23, 1], [1, 5, 2, 12, 1]] [1] Cost: 1575.376 to 1566.860 | Optimized: [1, 9, 15, 14, 13, 1] [2] Cost: 1428.148 to 1427.230 | Optimized: [1, 18, 10, 4, 0, 7, 1] [3] Cost: 1801.357 to 1782.980 | Optimized: [1, 19, 17, 23, 21, 1] [4] Cost: 1274.754 to 1272.297 | Optimized: [1, 12, 2, 5, 1] ACO RESULTS [1/295 vol./1566.860 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Nürnberg Hbf --> Berlin Hbf [2/260 vol./1427.230 km] Berlin Hbf -> Kiel Hbf -> Bremen Hbf -> Hannover Hbf -> Kassel-Wilhelmshöhe -> Dresden Hbf --> Berlin Hbf [3/270 vol./1782.980 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Freiburg Hbf -> Saarbrücken Hbf --> Berlin Hbf [4/205 vol./1272.297 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Aachen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6049.367 km.