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: 19 customers
- Kassel-Wilhelmshöhe (90 vol.)
- Düsseldorf Hbf (85 vol.)
- Frankfurt Hbf (20 vol.)
- Hannover Hbf (95 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (20 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (40 vol.)
- Bremen Hbf (80 vol.)
- Leipzig Hbf (90 vol.)
- Nürnberg Hbf (80 vol.)
- Karlsruhe Hbf (30 vol.)
- Ulm Hbf (60 vol.)
- Köln Hbf (55 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (20 vol.)
- Würzburg Hbf (50 vol.)
- Saarbrücken Hbf (75 vol.)
- Freiburg Hbf (25 vol.)
Tour 1
COST: 1976.005 km
LOAD: 290 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 60 vol.
- Stuttgart Hbf | 20 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 75 vol.
- Mainz Hbf | 20 vol.
- Frankfurt Hbf | 20 vol.
Tour 2
COST: 1576.672 km
LOAD: 295 vol.
- Köln Hbf | 55 vol.
- Würzburg Hbf | 50 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 90 vol.
- Dresden Hbf | 20 vol.
Tour 3
COST: 1174.274 km
LOAD: 270 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Düsseldorf Hbf | 85 vol.
- Hannover Hbf | 95 vol.
Tour 4
COST: 959.498 km
LOAD: 210 vol.
- Hamburg Hbf | 40 vol.
- Bremen Hbf | 80 vol.
- Kiel Hbf | 90 vol.
LOAD: 290 vol.
- München Hbf | 40 vol.
- Ulm Hbf | 60 vol.
- Stuttgart Hbf | 20 vol.
- Karlsruhe Hbf | 30 vol.
- Freiburg Hbf | 25 vol.
- Saarbrücken Hbf | 75 vol.
- Mainz Hbf | 20 vol.
- Frankfurt Hbf | 20 vol.
LOAD: 295 vol.
- Köln Hbf | 55 vol.
- Würzburg Hbf | 50 vol.
- Nürnberg Hbf | 80 vol.
- Leipzig Hbf | 90 vol.
- Dresden Hbf | 20 vol.
LOAD: 270 vol.
- Kassel-Wilhelmshöhe | 90 vol.
- Düsseldorf Hbf | 85 vol.
- Hannover Hbf | 95 vol.
LOAD: 210 vol.
- Hamburg Hbf | 40 vol.
- Bremen Hbf | 80 vol.
- Kiel Hbf | 90 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: 1065 vol. | Vehicle capacity: 300 vol. Loads: [90, 0, 85, 20, 95, 0, 20, 20, 40, 40, 80, 90, 0, 80, 30, 60, 55, 0, 90, 20, 50, 75, 0, 25] ITERATION Generation: #1 Best cost: 7017.081 | Path: [1, 0, 2, 16, 19, 3, 14, 1, 11, 7, 13, 20, 6, 23, 1, 8, 18, 10, 21, 1, 4, 15, 9, 1] Best cost: 6313.422 | Path: [1, 3, 19, 21, 14, 6, 15, 9, 23, 1, 7, 11, 0, 4, 1, 8, 18, 10, 2, 1, 13, 20, 16, 1] Best cost: 5875.778 | Path: [1, 9, 15, 6, 14, 23, 21, 19, 3, 1, 7, 11, 0, 4, 1, 8, 18, 10, 2, 1, 13, 20, 16, 1] Best cost: 5871.929 | Path: [1, 9, 15, 6, 14, 23, 21, 19, 3, 1, 11, 7, 13, 20, 16, 1, 8, 18, 10, 2, 1, 4, 0, 1] Best cost: 5849.261 | Path: [1, 3, 19, 21, 23, 14, 6, 15, 9, 1, 7, 11, 4, 10, 1, 8, 18, 2, 16, 1, 20, 13, 0, 1] Generation: #4 Best cost: 5845.707 | Path: [1, 9, 15, 6, 14, 23, 21, 19, 3, 1, 7, 11, 13, 20, 16, 1, 8, 18, 10, 2, 1, 4, 0, 1] Generation: #5 Best cost: 5796.942 | Path: [1, 9, 15, 6, 14, 23, 21, 19, 3, 1, 11, 7, 13, 20, 16, 1, 4, 0, 2, 1, 8, 18, 10, 1] OPTIMIZING each tour... Current: [[1, 9, 15, 6, 14, 23, 21, 19, 3, 1], [1, 11, 7, 13, 20, 16, 1], [1, 4, 0, 2, 1], [1, 8, 18, 10, 1]] [2] Cost: 1604.854 to 1576.672 | Optimized: [1, 16, 20, 13, 11, 7, 1] [3] Cost: 1241.018 to 1174.274 | Optimized: [1, 0, 2, 4, 1] [4] Cost: 975.065 to 959.498 | Optimized: [1, 8, 10, 18, 1] ACO RESULTS [1/290 vol./1976.005 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/295 vol./1576.672 km] Berlin Hbf -> Köln Hbf -> Würzburg Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/270 vol./1174.274 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Düsseldorf Hbf -> Hannover Hbf --> Berlin Hbf [4/210 vol./ 959.498 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5686.449 km.