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: 17 customers
- Düsseldorf Hbf (35 vol.)
- Frankfurt Hbf (100 vol.)
- Hannover Hbf (45 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (20 vol.)
- Dresden Hbf (20 vol.)
- Hamburg Hbf (40 vol.)
- Bremen Hbf (20 vol.)
- Dortmund Hbf (80 vol.)
- Nürnberg Hbf (45 vol.)
- Karlsruhe Hbf (30 vol.)
- Ulm Hbf (35 vol.)
- Köln Hbf (60 vol.)
- Kiel Hbf (65 vol.)
- Mainz Hbf (75 vol.)
- Würzburg Hbf (35 vol.)
- Osnabrück Hbf (95 vol.)
Tour 1
COST: 1470.124 km
LOAD: 290 vol.
- Mainz Hbf | 75 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 40 vol.
- Düsseldorf Hbf | 35 vol.
- Dortmund Hbf | 80 vol.
Tour 2
COST: 1621.985 km
LOAD: 285 vol.
- Würzburg Hbf | 35 vol.
- Frankfurt Hbf | 100 vol.
- Karlsruhe Hbf | 30 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 35 vol.
- Nürnberg Hbf | 45 vol.
- Dresden Hbf | 20 vol.
Tour 3
COST: 1113.837 km
LOAD: 265 vol.
- Hannover Hbf | 45 vol.
- Osnabrück Hbf | 95 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 65 vol.
LOAD: 290 vol.
- Mainz Hbf | 75 vol.
- Köln Hbf | 60 vol.
- Aachen Hbf | 40 vol.
- Düsseldorf Hbf | 35 vol.
- Dortmund Hbf | 80 vol.
LOAD: 285 vol.
- Würzburg Hbf | 35 vol.
- Frankfurt Hbf | 100 vol.
- Karlsruhe Hbf | 30 vol.
- Stuttgart Hbf | 20 vol.
- Ulm Hbf | 35 vol.
- Nürnberg Hbf | 45 vol.
- Dresden Hbf | 20 vol.
LOAD: 265 vol.
- Hannover Hbf | 45 vol.
- Osnabrück Hbf | 95 vol.
- Bremen Hbf | 20 vol.
- Hamburg Hbf | 40 vol.
- Kiel 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: [1] Berlin Hbf | Number of cities: 24 | Total loads: 840 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 35, 100, 45, 40, 20, 20, 40, 0, 20, 0, 80, 45, 30, 35, 60, 0, 65, 75, 35, 0, 95, 0] ITERATION Generation: #1 Best cost: 5215.285 | Path: [1, 2, 16, 5, 12, 4, 10, 7, 1, 8, 18, 22, 3, 1, 13, 20, 6, 14, 15, 19, 1] Best cost: 4970.040 | Path: [1, 3, 19, 14, 6, 15, 20, 1, 8, 10, 22, 12, 2, 7, 1, 18, 4, 16, 5, 13, 1] Best cost: 4952.303 | Path: [1, 6, 14, 3, 19, 16, 1, 7, 13, 20, 15, 2, 5, 12, 1, 8, 18, 10, 4, 22, 1] Best cost: 4751.068 | Path: [1, 12, 2, 16, 5, 19, 1, 7, 13, 20, 6, 14, 3, 15, 1, 4, 10, 8, 18, 22, 1] Best cost: 4535.548 | Path: [1, 15, 6, 14, 19, 3, 20, 1, 7, 13, 2, 16, 5, 12, 10, 1, 4, 22, 8, 18, 1] Best cost: 4426.269 | Path: [1, 12, 2, 16, 5, 19, 1, 7, 4, 22, 10, 8, 18, 1, 20, 3, 14, 6, 15, 13, 1] Best cost: 4372.701 | Path: [1, 12, 2, 16, 5, 19, 1, 7, 13, 20, 3, 14, 6, 15, 1, 4, 10, 22, 8, 18, 1] Best cost: 4302.295 | Path: [1, 12, 2, 16, 5, 19, 1, 7, 13, 20, 3, 14, 6, 15, 1, 8, 18, 10, 22, 4, 1] Generation: #2 Best cost: 4279.185 | Path: [1, 12, 2, 16, 5, 19, 1, 7, 13, 20, 3, 14, 6, 15, 1, 4, 22, 10, 8, 18, 1] OPTIMIZING each tour... Current: [[1, 12, 2, 16, 5, 19, 1], [1, 7, 13, 20, 3, 14, 6, 15, 1], [1, 4, 22, 10, 8, 18, 1]] [1] Cost: 1486.500 to 1470.124 | Optimized: [1, 19, 16, 5, 2, 12, 1] [2] Cost: 1678.848 to 1621.985 | Optimized: [1, 20, 3, 14, 6, 15, 13, 7, 1] ACO RESULTS [1/290 vol./1470.124 km] Berlin Hbf -> Mainz Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf [2/285 vol./1621.985 km] Berlin Hbf -> Würzburg Hbf -> Frankfurt Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/265 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4205.946 km.