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 (100 vol.)
- Düsseldorf Hbf (80 vol.)
- Frankfurt Hbf (85 vol.)
- Hannover Hbf (65 vol.)
- Stuttgart Hbf (35 vol.)
- Dresden Hbf (25 vol.)
- Dortmund Hbf (60 vol.)
- Karlsruhe Hbf (55 vol.)
- Ulm Hbf (50 vol.)
- Köln Hbf (60 vol.)
- Mannheim Hbf (20 vol.)
- Kiel Hbf (100 vol.)
- Würzburg Hbf (35 vol.)
- Saarbrücken Hbf (30 vol.)
- Osnabrück Hbf (60 vol.)
Tour 1
COST: 1628.19 km
LOAD: 290 vol.
- Saarbrücken Hbf | 30 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 80 vol.
- Dortmund Hbf | 60 vol.
- Osnabrück Hbf | 60 vol.
Tour 2
COST: 1348.971 km
LOAD: 290 vol.
- Dresden Hbf | 25 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Hannover Hbf | 65 vol.
- Kiel Hbf | 100 vol.
Tour 3
COST: 1543.107 km
LOAD: 280 vol.
- Würzburg Hbf | 35 vol.
- Frankfurt Hbf | 85 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 55 vol.
- Stuttgart Hbf | 35 vol.
- Ulm Hbf | 50 vol.
LOAD: 290 vol.
- Saarbrücken Hbf | 30 vol.
- Köln Hbf | 60 vol.
- Düsseldorf Hbf | 80 vol.
- Dortmund Hbf | 60 vol.
- Osnabrück Hbf | 60 vol.
LOAD: 290 vol.
- Dresden Hbf | 25 vol.
- Kassel-Wilhelmshöhe | 100 vol.
- Hannover Hbf | 65 vol.
- Kiel Hbf | 100 vol.
LOAD: 280 vol.
- Würzburg Hbf | 35 vol.
- Frankfurt Hbf | 85 vol.
- Mannheim Hbf | 20 vol.
- Karlsruhe Hbf | 55 vol.
- Stuttgart Hbf | 35 vol.
- Ulm Hbf | 50 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: 860 vol. | Vehicle capacity: 300 vol. Loads: [100, 0, 80, 85, 65, 0, 35, 25, 0, 0, 0, 0, 60, 0, 55, 50, 60, 20, 100, 0, 35, 30, 60, 0] ITERATION Generation: #1 Best cost: 5509.737 | Path: [1, 0, 22, 12, 2, 1, 7, 6, 14, 17, 3, 20, 21, 1, 4, 18, 16, 15, 1] Best cost: 5247.998 | Path: [1, 2, 16, 12, 0, 1, 4, 22, 18, 20, 6, 1, 7, 3, 17, 14, 21, 15, 1] Best cost: 4842.229 | Path: [1, 3, 17, 14, 6, 15, 20, 1, 7, 0, 12, 2, 21, 1, 4, 22, 16, 18, 1] Best cost: 4692.633 | Path: [1, 20, 3, 17, 14, 6, 15, 1, 7, 0, 2, 16, 21, 1, 4, 22, 12, 18, 1] Best cost: 4593.728 | Path: [1, 22, 12, 2, 16, 17, 1, 7, 0, 4, 18, 1, 20, 3, 21, 14, 6, 15, 1] Best cost: 4530.010 | Path: [1, 22, 12, 2, 16, 21, 1, 7, 0, 4, 18, 1, 20, 3, 17, 14, 6, 15, 1] OPTIMIZING each tour... Current: [[1, 22, 12, 2, 16, 21, 1], [1, 7, 0, 4, 18, 1], [1, 20, 3, 17, 14, 6, 15, 1]] [1] Cost: 1637.932 to 1628.190 | Optimized: [1, 21, 16, 2, 12, 22, 1] ACO RESULTS [1/290 vol./1628.190 km] Berlin Hbf -> Saarbrücken Hbf -> Köln Hbf -> Düsseldorf Hbf -> Dortmund Hbf -> Osnabrück Hbf --> Berlin Hbf [2/290 vol./1348.971 km] Berlin Hbf -> Dresden Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Kiel Hbf --> Berlin Hbf [3/280 vol./1543.107 km] Berlin Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4520.268 km.