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 (25 vol.)
- Düsseldorf Hbf (60 vol.)
- Frankfurt Hbf (20 vol.)
- Hannover Hbf (70 vol.)
- Hamburg Hbf (100 vol.)
- München Hbf (85 vol.)
- Leipzig Hbf (70 vol.)
- Dortmund Hbf (30 vol.)
- Nürnberg Hbf (55 vol.)
- Ulm Hbf (25 vol.)
- Kiel Hbf (25 vol.)
- Mainz Hbf (85 vol.)
- Würzburg Hbf (75 vol.)
- Saarbrücken Hbf (45 vol.)
- Freiburg Hbf (70 vol.)
Tour 1
COST: 1745.727 km
LOAD: 295 vol.
- Frankfurt Hbf | 20 vol.
- Mainz Hbf | 85 vol.
- Saarbrücken Hbf | 45 vol.
- Freiburg Hbf | 70 vol.
- Würzburg Hbf | 75 vol.
Tour 2
COST: 1237.299 km
LOAD: 290 vol.
- Leipzig Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 25 vol.
- Hannover Hbf | 70 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 25 vol.
Tour 3
COST: 1794.7 km
LOAD: 255 vol.
- Nürnberg Hbf | 55 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 25 vol.
- Düsseldorf Hbf | 60 vol.
- Dortmund Hbf | 30 vol.
LOAD: 295 vol.
- Frankfurt Hbf | 20 vol.
- Mainz Hbf | 85 vol.
- Saarbrücken Hbf | 45 vol.
- Freiburg Hbf | 70 vol.
- Würzburg Hbf | 75 vol.
LOAD: 290 vol.
- Leipzig Hbf | 70 vol.
- Kassel-Wilhelmshöhe | 25 vol.
- Hannover Hbf | 70 vol.
- Hamburg Hbf | 100 vol.
- Kiel Hbf | 25 vol.
LOAD: 255 vol.
- Nürnberg Hbf | 55 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 25 vol.
- Düsseldorf Hbf | 60 vol.
- Dortmund Hbf | 30 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: [25, 0, 60, 20, 70, 0, 0, 0, 100, 85, 0, 70, 30, 55, 0, 25, 0, 0, 25, 85, 75, 45, 0, 70] ITERATION Generation: #1 Best cost: 5933.529 | Path: [1, 0, 4, 8, 18, 12, 3, 15, 1, 11, 13, 20, 19, 1, 9, 21, 23, 2, 1] Best cost: 5455.925 | Path: [1, 2, 12, 0, 4, 8, 1, 11, 13, 20, 3, 21, 15, 1, 18, 19, 23, 9, 1] Best cost: 5194.018 | Path: [1, 4, 8, 18, 12, 2, 1, 11, 0, 3, 19, 20, 15, 1, 13, 9, 23, 21, 1] Best cost: 5168.175 | Path: [1, 8, 18, 4, 0, 2, 3, 1, 11, 13, 20, 19, 1, 12, 21, 23, 15, 9, 1] Best cost: 5156.082 | Path: [1, 11, 13, 20, 3, 21, 12, 1, 8, 18, 4, 0, 2, 1, 9, 15, 23, 19, 1] Best cost: 5071.670 | Path: [1, 20, 13, 9, 15, 3, 12, 1, 11, 0, 4, 8, 18, 1, 2, 19, 21, 23, 1] Best cost: 4973.333 | Path: [1, 0, 12, 2, 3, 19, 21, 15, 1, 11, 4, 8, 18, 1, 20, 13, 9, 23, 1] Best cost: 4926.462 | Path: [1, 8, 18, 4, 12, 2, 1, 11, 0, 3, 19, 21, 13, 1, 9, 15, 23, 20, 1] Best cost: 4865.062 | Path: [1, 13, 20, 3, 19, 21, 1, 11, 0, 4, 8, 18, 1, 12, 2, 23, 15, 9, 1] Best cost: 4859.878 | Path: [1, 11, 20, 13, 9, 1, 4, 8, 18, 12, 2, 1, 0, 3, 19, 21, 23, 15, 1] Best cost: 4857.741 | Path: [1, 21, 19, 3, 20, 13, 1, 11, 0, 4, 8, 18, 1, 12, 2, 23, 15, 9, 1] Best cost: 4777.726 | Path: [1, 3, 19, 21, 23, 20, 1, 11, 0, 4, 8, 18, 1, 13, 9, 15, 2, 12, 1] OPTIMIZING each tour... Current: [[1, 3, 19, 21, 23, 20, 1], [1, 11, 0, 4, 8, 18, 1], [1, 13, 9, 15, 2, 12, 1]] No changes made. ACO RESULTS [1/295 vol./1745.727 km] Berlin Hbf -> Frankfurt Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [2/290 vol./1237.299 km] Berlin Hbf -> Leipzig Hbf -> Kassel-Wilhelmshöhe -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/255 vol./1794.700 km] Berlin Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4777.726 km.