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: 16 customers
- Berlin Hbf (50 vol.)
- Düsseldorf Hbf (65 vol.)
- Frankfurt Hbf (40 vol.)
- Hannover Hbf (95 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (90 vol.)
- Hamburg Hbf (70 vol.)
- München Hbf (95 vol.)
- Dortmund Hbf (25 vol.)
- Nürnberg Hbf (35 vol.)
- Ulm Hbf (100 vol.)
- Köln Hbf (65 vol.)
- Mainz Hbf (70 vol.)
- Würzburg Hbf (55 vol.)
- Saarbrücken Hbf (50 vol.)
- Osnabrück Hbf (95 vol.)
Tour 1
COST: 1374.308 km
LOAD: 400 vol.
- Dortmund Hbf | 25 vol.
- Düsseldorf Hbf | 65 vol.
- Osnabrück Hbf | 95 vol.
- Hannover Hbf | 95 vol.
- Hamburg Hbf | 70 vol.
- Berlin Hbf | 50 vol.
Tour 2
COST: 1078.186 km
LOAD: 375 vol.
- Nürnberg Hbf | 35 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 90 vol.
- Würzburg Hbf | 55 vol.
Tour 3
COST: 964.817 km
LOAD: 255 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 70 vol.
- Saarbrücken Hbf | 50 vol.
- Aachen Hbf | 30 vol.
- Köln Hbf | 65 vol.
LOAD: 400 vol.
- Dortmund Hbf | 25 vol.
- Düsseldorf Hbf | 65 vol.
- Osnabrück Hbf | 95 vol.
- Hannover Hbf | 95 vol.
- Hamburg Hbf | 70 vol.
- Berlin Hbf | 50 vol.
LOAD: 375 vol.
- Nürnberg Hbf | 35 vol.
- München Hbf | 95 vol.
- Ulm Hbf | 100 vol.
- Stuttgart Hbf | 90 vol.
- Würzburg Hbf | 55 vol.
LOAD: 255 vol.
- Frankfurt Hbf | 40 vol.
- Mainz Hbf | 70 vol.
- Saarbrücken Hbf | 50 vol.
- Aachen Hbf | 30 vol.
- Köln 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: [0] Kassel-Wilhelmshöhe | Number of cities: 24 | Total loads: 1030 vol. | Vehicle capacity: 400 vol. Loads: [0, 50, 65, 40, 95, 30, 90, 0, 70, 95, 0, 0, 25, 35, 0, 100, 65, 0, 0, 70, 55, 50, 95, 0] ITERATION Generation: #1 Best cost: 4721.482 | Path: [0, 1, 4, 22, 12, 2, 16, 0, 20, 3, 19, 21, 6, 9, 0, 8, 13, 15, 5, 0] Best cost: 4077.662 | Path: [0, 2, 16, 5, 12, 22, 4, 0, 3, 19, 20, 13, 9, 15, 0, 6, 21, 8, 1, 0] Best cost: 3844.254 | Path: [0, 3, 19, 21, 6, 15, 13, 0, 4, 22, 12, 2, 16, 5, 0, 20, 9, 1, 8, 0] Best cost: 3592.567 | Path: [0, 22, 4, 8, 1, 13, 20, 0, 12, 2, 16, 5, 21, 19, 3, 0, 6, 15, 9, 0] Best cost: 3499.722 | Path: [0, 1, 8, 4, 22, 12, 2, 0, 20, 13, 9, 15, 6, 0, 3, 19, 21, 16, 5, 0] Best cost: 3440.058 | Path: [0, 1, 8, 4, 22, 12, 2, 0, 20, 13, 9, 15, 6, 0, 3, 19, 21, 5, 16, 0] OPTIMIZING each tour... Current: [[0, 1, 8, 4, 22, 12, 2, 0], [0, 20, 13, 9, 15, 6, 0], [0, 3, 19, 21, 5, 16, 0]] [1] Cost: 1389.914 to 1374.308 | Optimized: [0, 12, 2, 22, 4, 8, 1, 0] [2] Cost: 1085.327 to 1078.186 | Optimized: [0, 13, 9, 15, 6, 20, 0] ACO RESULTS [1/400 vol./1374.308 km] Kassel-Wilhelmshöhe -> Dortmund Hbf -> Düsseldorf Hbf -> Osnabrück Hbf -> Hannover Hbf -> Hamburg Hbf -> Berlin Hbf --> Kassel-Wilhelmshöhe [2/375 vol./1078.186 km] Kassel-Wilhelmshöhe -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Kassel-Wilhelmshöhe [3/255 vol./ 964.817 km] Kassel-Wilhelmshöhe -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Aachen Hbf -> Köln Hbf --> Kassel-Wilhelmshöhe OPTIMIZATION RESULT: 3 tours | 3417.311 km.