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: 19 customers
- Berlin Hbf (90 vol.)
- Frankfurt Hbf (45 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (100 vol.)
- Dresden Hbf (70 vol.)
- Hamburg Hbf (30 vol.)
- München Hbf (100 vol.)
- Bremen Hbf (70 vol.)
- Dortmund Hbf (100 vol.)
- Nürnberg Hbf (50 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (65 vol.)
- Köln Hbf (75 vol.)
- Mannheim Hbf (40 vol.)
- Kiel Hbf (50 vol.)
- Mainz Hbf (80 vol.)
- Würzburg Hbf (70 vol.)
- Osnabrück Hbf (20 vol.)
- Freiburg Hbf (95 vol.)
Tour 1
COST: 1078.186 km
LOAD: 385 vol.
- Nürnberg Hbf | 50 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 100 vol.
- Würzburg Hbf | 70 vol.
Tour 2
COST: 1294.723 km
LOAD: 385 vol.
- Frankfurt Hbf | 45 vol.
- Mannheim Hbf | 40 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 95 vol.
- Mainz Hbf | 80 vol.
- Aachen Hbf | 70 vol.
Tour 3
COST: 1433.199 km
LOAD: 330 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 50 vol.
- Berlin Hbf | 90 vol.
- Dresden Hbf | 70 vol.
Tour 4
COST: 498.486 km
LOAD: 175 vol.
- Dortmund Hbf | 100 vol.
- Köln Hbf | 75 vol.
LOAD: 385 vol.
- Nürnberg Hbf | 50 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 65 vol.
- Stuttgart Hbf | 100 vol.
- Würzburg Hbf | 70 vol.
LOAD: 385 vol.
- Frankfurt Hbf | 45 vol.
- Mannheim Hbf | 40 vol.
- Karlsruhe Hbf | 55 vol.
- Freiburg Hbf | 95 vol.
- Mainz Hbf | 80 vol.
- Aachen Hbf | 70 vol.
LOAD: 330 vol.
- Osnabrück Hbf | 20 vol.
- Bremen Hbf | 70 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 50 vol.
- Berlin Hbf | 90 vol.
- Dresden Hbf | 70 vol.
LOAD: 175 vol.
- Dortmund Hbf | 100 vol.
- Köln Hbf | 75 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: 1275 vol. | Vehicle capacity: 400 vol. Loads: [0, 90, 0, 45, 0, 70, 100, 70, 30, 100, 70, 0, 100, 50, 55, 65, 75, 40, 50, 80, 70, 0, 20, 95] ITERATION Generation: #1 Best cost: 5510.835 | Path: [0, 1, 7, 20, 3, 19, 17, 0, 12, 16, 5, 22, 10, 8, 0, 13, 9, 15, 6, 14, 0, 18, 23, 0] Best cost: 5256.082 | Path: [0, 3, 19, 17, 14, 6, 15, 0, 12, 16, 5, 22, 10, 8, 0, 20, 13, 9, 23, 7, 0, 18, 1, 0] Best cost: 4946.694 | Path: [0, 7, 1, 8, 18, 10, 22, 5, 0, 16, 12, 3, 19, 17, 14, 0, 20, 13, 9, 15, 6, 0, 23, 0] Best cost: 4937.760 | Path: [0, 15, 6, 14, 17, 19, 3, 0, 22, 10, 8, 18, 1, 7, 13, 0, 20, 5, 16, 12, 0, 23, 9, 0] Best cost: 4728.456 | Path: [0, 18, 8, 10, 22, 12, 16, 3, 0, 20, 13, 9, 15, 6, 0, 19, 17, 14, 23, 5, 0, 7, 1, 0] Best cost: 4709.861 | Path: [0, 8, 18, 10, 22, 12, 16, 3, 0, 20, 13, 9, 15, 6, 0, 19, 17, 14, 23, 5, 0, 7, 1, 0] Best cost: 4702.056 | Path: [0, 22, 10, 8, 18, 1, 7, 13, 0, 12, 16, 5, 19, 3, 0, 20, 6, 14, 17, 23, 0, 9, 15, 0] Best cost: 4566.749 | Path: [0, 22, 10, 8, 18, 1, 7, 20, 0, 12, 16, 5, 3, 19, 0, 13, 9, 15, 6, 14, 0, 17, 23, 0] Best cost: 4521.307 | Path: [0, 22, 10, 8, 18, 1, 7, 20, 0, 12, 16, 5, 19, 3, 0, 13, 9, 15, 6, 14, 0, 17, 23, 0] Generation: #4 Best cost: 4326.582 | Path: [0, 20, 13, 9, 15, 6, 0, 3, 19, 17, 14, 23, 5, 0, 22, 10, 8, 18, 1, 7, 0, 12, 16, 0] OPTIMIZING each tour... Current: [[0, 20, 13, 9, 15, 6, 0], [0, 3, 19, 17, 14, 23, 5, 0], [0, 22, 10, 8, 18, 1, 7, 0], [0, 12, 16, 0]] [1] Cost: 1085.327 to 1078.186 | Optimized: [0, 13, 9, 15, 6, 20, 0] [2] Cost: 1309.570 to 1294.723 | Optimized: [0, 3, 17, 14, 23, 19, 5, 0] ACO RESULTS [1/385 vol./1078.186 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [2/385 vol./1294.723 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Mainz Hbf -> Aachen Hbf --> Kassel-Wilhelmshöhe [3/330 vol./1433.199 km] Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf -> Berlin Hbf -> Dresden Hbf --> Kassel-Wilhelmshöhe [4/175 vol./ 498.486 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 4 tours | 4304.594 km.