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 (80 vol.)
- Aachen Hbf (40 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (25 vol.)
- München Hbf (25 vol.)
- Bremen Hbf (95 vol.)
- Leipzig Hbf (65 vol.)
- Dortmund Hbf (20 vol.)
- Nürnberg Hbf (85 vol.)
- Ulm Hbf (100 vol.)
- Köln Hbf (35 vol.)
- Mainz Hbf (50 vol.)
- Würzburg Hbf (75 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1529.159 km
LOAD: 300 vol.
- Würzburg Hbf | 75 vol.
- Mainz Hbf | 50 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 40 vol.
- Düsseldorf Hbf | 80 vol.
- Dortmund Hbf | 20 vol.
Tour 2
COST: 1520.359 km
LOAD: 300 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 100 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 65 vol.
- Dresden Hbf | 25 vol.
Tour 3
COST: 1688.639 km
LOAD: 235 vol.
- Stuttgart Hbf | 95 vol.
- Freiburg Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 55 vol.
Tour 4
COST: 781.807 km
LOAD: 95 vol.
- Bremen Hbf | 95 vol.
LOAD: 300 vol.
- Würzburg Hbf | 75 vol.
- Mainz Hbf | 50 vol.
- Köln Hbf | 35 vol.
- Aachen Hbf | 40 vol.
- Düsseldorf Hbf | 80 vol.
- Dortmund Hbf | 20 vol.
LOAD: 300 vol.
- München Hbf | 25 vol.
- Ulm Hbf | 100 vol.
- Nürnberg Hbf | 85 vol.
- Leipzig Hbf | 65 vol.
- Dresden Hbf | 25 vol.
LOAD: 235 vol.
- Stuttgart Hbf | 95 vol.
- Freiburg Hbf | 85 vol.
- Kassel-Wilhelmshöhe | 55 vol.
LOAD: 95 vol.
- Bremen Hbf | 95 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: 930 vol. | Vehicle capacity: 300 vol. Loads: [55, 0, 80, 0, 0, 40, 95, 25, 0, 25, 95, 65, 20, 85, 0, 100, 35, 0, 0, 50, 75, 0, 0, 85] ITERATION Generation: #1 Best cost: 6687.988 | Path: [1, 0, 20, 13, 9, 5, 12, 1, 7, 11, 10, 2, 16, 1, 6, 15, 23, 1, 19, 1] Best cost: 6387.669 | Path: [1, 5, 2, 16, 12, 0, 11, 1, 7, 13, 20, 6, 1, 10, 19, 15, 9, 1, 23, 1] Best cost: 6318.226 | Path: [1, 6, 15, 9, 20, 1, 11, 7, 13, 19, 16, 5, 1, 0, 12, 2, 10, 1, 23, 1] Best cost: 6129.890 | Path: [1, 9, 15, 6, 20, 1, 11, 7, 13, 19, 16, 5, 1, 0, 12, 2, 10, 1, 23, 1] Best cost: 6118.732 | Path: [1, 9, 15, 6, 20, 1, 7, 11, 13, 19, 16, 5, 1, 10, 12, 2, 0, 1, 23, 1] Best cost: 6103.137 | Path: [1, 10, 12, 2, 16, 5, 7, 1, 11, 0, 20, 13, 1, 19, 6, 15, 9, 1, 23, 1] Best cost: 5925.970 | Path: [1, 23, 15, 6, 12, 1, 7, 11, 20, 13, 9, 1, 16, 2, 5, 19, 0, 1, 10, 1] Best cost: 5776.830 | Path: [1, 15, 6, 20, 7, 1, 11, 13, 9, 23, 16, 1, 0, 12, 2, 5, 19, 1, 10, 1] Generation: #2 Best cost: 5639.371 | Path: [1, 12, 2, 16, 5, 19, 20, 1, 11, 7, 13, 9, 15, 1, 0, 6, 23, 1, 10, 1] OPTIMIZING each tour... Current: [[1, 12, 2, 16, 5, 19, 20, 1], [1, 11, 7, 13, 9, 15, 1], [1, 0, 6, 23, 1], [1, 10, 1]] [1] Cost: 1544.097 to 1529.159 | Optimized: [1, 20, 19, 16, 5, 2, 12, 1] [2] Cost: 1553.708 to 1520.359 | Optimized: [1, 9, 15, 13, 11, 7, 1] [3] Cost: 1759.759 to 1688.639 | Optimized: [1, 6, 23, 0, 1] ACO RESULTS [1/300 vol./1529.159 km] Berlin Hbf -> Würzburg Hbf -> Mainz Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf [2/300 vol./1520.359 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/235 vol./1688.639 km] Berlin Hbf -> Stuttgart Hbf -> Freiburg Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf [4/ 95 vol./ 781.807 km] Berlin Hbf -> Bremen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5519.964 km.