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: 15 customers
- Kassel-Wilhelmshöhe (55 vol.)
- Frankfurt Hbf (60 vol.)
- Hannover Hbf (40 vol.)
- Aachen Hbf (80 vol.)
- Stuttgart Hbf (100 vol.)
- Hamburg Hbf (55 vol.)
- München Hbf (100 vol.)
- Nürnberg Hbf (70 vol.)
- Karlsruhe Hbf (95 vol.)
- Ulm Hbf (40 vol.)
- Kiel Hbf (40 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (60 vol.)
- Osnabrück Hbf (30 vol.)
- Freiburg Hbf (50 vol.)
Tour 1
COST: 1445.778 km
LOAD: 300 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 100 vol.
- Würzburg Hbf | 60 vol.
Tour 2
COST: 1408.85 km
LOAD: 280 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Osnabrück Hbf | 30 vol.
- Hannover Hbf | 40 vol.
Tour 3
COST: 1926.247 km
LOAD: 295 vol.
- Aachen Hbf | 80 vol.
- Karlsruhe Hbf | 95 vol.
- Freiburg Hbf | 50 vol.
- Nürnberg Hbf | 70 vol.
Tour 4
COST: 732.557 km
LOAD: 95 vol.
- Hamburg Hbf | 55 vol.
- Kiel Hbf | 40 vol.
LOAD: 300 vol.
- München Hbf | 100 vol.
- Ulm Hbf | 40 vol.
- Stuttgart Hbf | 100 vol.
- Würzburg Hbf | 60 vol.
LOAD: 280 vol.
- Mainz Hbf | 95 vol.
- Frankfurt Hbf | 60 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Osnabrück Hbf | 30 vol.
- Hannover Hbf | 40 vol.
LOAD: 295 vol.
- Aachen Hbf | 80 vol.
- Karlsruhe Hbf | 95 vol.
- Freiburg Hbf | 50 vol.
- Nürnberg Hbf | 70 vol.
LOAD: 95 vol.
- Hamburg Hbf | 55 vol.
- Kiel Hbf | 40 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: 970 vol. | Vehicle capacity: 300 vol. Loads: [55, 0, 0, 60, 40, 80, 100, 0, 55, 100, 0, 0, 0, 70, 95, 40, 0, 0, 40, 95, 60, 0, 30, 50] ITERATION Generation: #1 Best cost: 6890.281 | Path: [1, 0, 3, 19, 20, 22, 1, 8, 18, 4, 5, 15, 1, 9, 13, 6, 1, 14, 23, 1] Best cost: 6063.053 | Path: [1, 3, 19, 20, 13, 1, 8, 18, 4, 22, 0, 5, 1, 15, 6, 14, 23, 1, 9, 1] Best cost: 6056.919 | Path: [1, 19, 3, 20, 13, 1, 8, 18, 4, 22, 0, 5, 1, 15, 6, 14, 23, 1, 9, 1] Best cost: 5962.885 | Path: [1, 18, 8, 4, 22, 5, 0, 1, 3, 19, 14, 23, 1, 13, 20, 6, 15, 1, 9, 1] Generation: #3 Best cost: 5525.092 | Path: [1, 9, 15, 6, 20, 1, 4, 22, 0, 3, 19, 1, 13, 14, 23, 5, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 20, 1], [1, 4, 22, 0, 3, 19, 1], [1, 13, 14, 23, 5, 1], [1, 8, 18, 1]] [2] Cost: 1412.301 to 1408.850 | Optimized: [1, 19, 3, 0, 22, 4, 1] [3] Cost: 1934.456 to 1926.247 | Optimized: [1, 5, 14, 23, 13, 1] ACO RESULTS [1/300 vol./1445.778 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [2/280 vol./1408.850 km] Berlin Hbf -> Mainz Hbf -> Frankfurt Hbf -> Kassel-Wilhelmshöhe -> Osnabrück Hbf -> Hannover Hbf --> Berlin Hbf [3/295 vol./1926.247 km] Berlin Hbf -> Aachen Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Nürnberg Hbf --> Berlin Hbf [4/ 95 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5513.432 km.