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.)
- Düsseldorf Hbf (25 vol.)
- Frankfurt Hbf (75 vol.)
- Dresden Hbf (85 vol.)
- Hamburg Hbf (30 vol.)
- Dortmund Hbf (25 vol.)
- Karlsruhe Hbf (90 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (100 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (95 vol.)
- Würzburg Hbf (35 vol.)
- Saarbrücken Hbf (75 vol.)
- Osnabrück Hbf (80 vol.)
- Freiburg Hbf (100 vol.)
Tour 1
COST: 1617.009 km
LOAD: 295 vol.
- Mainz Hbf | 95 vol.
- Mannheim Hbf | 100 vol.
- Saarbrücken Hbf | 75 vol.
- Düsseldorf Hbf | 25 vol.
Tour 2
COST: 1448.846 km
LOAD: 300 vol.
- Dresden Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Dortmund Hbf | 25 vol.
- Köln Hbf | 55 vol.
- Osnabrück Hbf | 80 vol.
Tour 3
COST: 1617.556 km
LOAD: 300 vol.
- Frankfurt Hbf | 75 vol.
- Karlsruhe Hbf | 90 vol.
- Freiburg Hbf | 100 vol.
- Würzburg Hbf | 35 vol.
Tour 4
COST: 732.557 km
LOAD: 120 vol.
- Hamburg Hbf | 30 vol.
- Kiel Hbf | 90 vol.
LOAD: 295 vol.
- Mainz Hbf | 95 vol.
- Mannheim Hbf | 100 vol.
- Saarbrücken Hbf | 75 vol.
- Düsseldorf Hbf | 25 vol.
LOAD: 300 vol.
- Dresden Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 55 vol.
- Dortmund Hbf | 25 vol.
- Köln Hbf | 55 vol.
- Osnabrück Hbf | 80 vol.
LOAD: 300 vol.
- Frankfurt Hbf | 75 vol.
- Karlsruhe Hbf | 90 vol.
- Freiburg Hbf | 100 vol.
- Würzburg Hbf | 35 vol.
LOAD: 120 vol.
- Hamburg Hbf | 30 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: 1015 vol. | Vehicle capacity: 300 vol. Loads: [55, 0, 25, 75, 0, 0, 0, 85, 30, 0, 0, 0, 25, 0, 90, 0, 55, 100, 90, 95, 35, 75, 80, 100] ITERATION Generation: #1 Best cost: 6672.112 | Path: [1, 0, 20, 3, 19, 2, 1, 7, 22, 12, 16, 8, 1, 18, 17, 14, 1, 21, 23, 1] Best cost: 6459.034 | Path: [1, 2, 16, 12, 22, 0, 8, 1, 7, 20, 3, 19, 1, 18, 21, 14, 1, 17, 23, 1] Best cost: 6342.218 | Path: [1, 7, 0, 12, 2, 16, 20, 1, 8, 18, 22, 3, 1, 14, 17, 19, 1, 23, 21, 1] Best cost: 6258.791 | Path: [1, 8, 18, 0, 12, 2, 16, 1, 7, 20, 3, 19, 1, 22, 17, 14, 1, 23, 21, 1] Best cost: 5852.638 | Path: [1, 12, 2, 16, 19, 3, 1, 7, 20, 17, 21, 1, 8, 18, 22, 0, 1, 14, 23, 1] Best cost: 5824.190 | Path: [1, 23, 14, 17, 1, 7, 20, 3, 19, 1, 8, 18, 12, 2, 16, 21, 1, 0, 22, 1] Best cost: 5564.976 | Path: [1, 21, 17, 19, 2, 1, 7, 0, 12, 16, 22, 1, 20, 3, 14, 23, 1, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 21, 17, 19, 2, 1], [1, 7, 0, 12, 16, 22, 1], [1, 20, 3, 14, 23, 1], [1, 8, 18, 1]] [1] Cost: 1709.439 to 1617.009 | Optimized: [1, 19, 17, 21, 2, 1] [3] Cost: 1674.134 to 1617.556 | Optimized: [1, 3, 14, 23, 20, 1] ACO RESULTS [1/295 vol./1617.009 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Saarbrücken Hbf -> Düsseldorf Hbf --> Berlin Hbf [2/300 vol./1448.846 km] Berlin Hbf -> Dresden Hbf -> Kassel-Wilhelmshöhe -> Dortmund Hbf -> Köln Hbf -> Osnabrück Hbf --> Berlin Hbf [3/300 vol./1617.556 km] Berlin Hbf -> Frankfurt Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [4/120 vol./ 732.557 km] Berlin Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5415.968 km.