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: 22 customers
- Kassel-Wilhelmshöhe (20 vol.)
- Düsseldorf Hbf (95 vol.)
- Frankfurt Hbf (50 vol.)
- Hannover Hbf (30 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (65 vol.)
- Hamburg Hbf (40 vol.)
- München Hbf (80 vol.)
- Bremen Hbf (80 vol.)
- Leipzig Hbf (50 vol.)
- Dortmund Hbf (35 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (85 vol.)
- Ulm Hbf (75 vol.)
- Köln Hbf (75 vol.)
- Mannheim Hbf (25 vol.)
- Kiel Hbf (90 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (30 vol.)
- Saarbrücken Hbf (100 vol.)
- Osnabrück Hbf (40 vol.)
- Freiburg Hbf (55 vol.)
Tour 1
COST: 1526.766 km
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 85 vol.
- Stuttgart Hbf | 95 vol.
- Ulm Hbf | 75 vol.
Tour 2
COST: 1507.756 km
LOAD: 285 vol.
- Würzburg Hbf | 30 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 80 vol.
- Leipzig Hbf | 50 vol.
- Dresden Hbf | 65 vol.
Tour 3
COST: 1113.837 km
LOAD: 280 vol.
- Hannover Hbf | 30 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 90 vol.
Tour 4
COST: 1334.618 km
LOAD: 255 vol.
- Dortmund Hbf | 35 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 75 vol.
- Frankfurt Hbf | 50 vol.
Tour 5
COST: 1730.787 km
LOAD: 255 vol.
- Mainz Hbf | 100 vol.
- Saarbrücken Hbf | 100 vol.
- Freiburg Hbf | 55 vol.
LOAD: 300 vol.
- Kassel-Wilhelmshöhe | 20 vol.
- Mannheim Hbf | 25 vol.
- Karlsruhe Hbf | 85 vol.
- Stuttgart Hbf | 95 vol.
- Ulm Hbf | 75 vol.
LOAD: 285 vol.
- Würzburg Hbf | 30 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 80 vol.
- Leipzig Hbf | 50 vol.
- Dresden Hbf | 65 vol.
LOAD: 280 vol.
- Hannover Hbf | 30 vol.
- Osnabrück Hbf | 40 vol.
- Bremen Hbf | 80 vol.
- Hamburg Hbf | 40 vol.
- Kiel Hbf | 90 vol.
LOAD: 255 vol.
- Dortmund Hbf | 35 vol.
- Düsseldorf Hbf | 95 vol.
- Köln Hbf | 75 vol.
- Frankfurt Hbf | 50 vol.
LOAD: 255 vol.
- Mainz Hbf | 100 vol.
- Saarbrücken Hbf | 100 vol.
- Freiburg Hbf | 55 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: 1375 vol. | Vehicle capacity: 300 vol. Loads: [20, 0, 95, 50, 30, 0, 95, 65, 40, 80, 80, 50, 35, 60, 85, 75, 75, 25, 90, 100, 30, 100, 40, 55] ITERATION Generation: #1 Best cost: 7843.440 | Path: [1, 0, 19, 3, 17, 14, 1, 11, 7, 13, 20, 6, 1, 8, 18, 10, 4, 22, 1, 12, 2, 16, 23, 1, 9, 15, 21, 1] Best cost: 7780.838 | Path: [1, 3, 19, 17, 14, 20, 1, 11, 7, 13, 9, 0, 1, 8, 18, 10, 4, 22, 1, 12, 2, 16, 6, 1, 15, 23, 21, 1] Best cost: 7749.589 | Path: [1, 8, 18, 10, 22, 4, 0, 1, 11, 7, 13, 20, 3, 17, 1, 12, 2, 16, 14, 1, 6, 15, 9, 1, 19, 21, 23, 1] Best cost: 7707.635 | Path: [1, 11, 7, 13, 20, 3, 17, 0, 1, 8, 18, 10, 22, 4, 1, 12, 2, 16, 14, 1, 9, 15, 6, 1, 21, 19, 23, 1] Best cost: 7342.962 | Path: [1, 12, 2, 16, 3, 17, 0, 1, 11, 7, 9, 15, 20, 1, 4, 22, 10, 8, 18, 1, 13, 6, 14, 23, 1, 19, 21, 1] Best cost: 7293.113 | Path: [1, 17, 14, 6, 15, 0, 1, 11, 7, 20, 3, 19, 1, 4, 22, 10, 8, 18, 1, 13, 9, 23, 21, 1, 12, 2, 16, 1] Generation: #2 Best cost: 7273.990 | Path: [1, 15, 6, 14, 17, 0, 1, 11, 7, 20, 13, 9, 1, 8, 18, 10, 22, 4, 1, 12, 2, 16, 3, 1, 19, 21, 23, 1] OPTIMIZING each tour... Current: [[1, 15, 6, 14, 17, 0, 1], [1, 11, 7, 20, 13, 9, 1], [1, 8, 18, 10, 22, 4, 1], [1, 12, 2, 16, 3, 1], [1, 19, 21, 23, 1]] [1] Cost: 1529.410 to 1526.766 | Optimized: [1, 0, 17, 14, 6, 15, 1] [2] Cost: 1542.228 to 1507.756 | Optimized: [1, 20, 13, 9, 11, 7, 1] [3] Cost: 1136.947 to 1113.837 | Optimized: [1, 4, 22, 10, 8, 18, 1] ACO RESULTS [1/300 vol./1526.766 km] Berlin Hbf -> Kassel-Wilhelmshöhe -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Ulm Hbf --> Berlin Hbf [2/285 vol./1507.756 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf -> Leipzig Hbf -> Dresden Hbf --> Berlin Hbf [3/280 vol./1113.837 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [4/255 vol./1334.618 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Köln Hbf -> Frankfurt Hbf --> Berlin Hbf [5/255 vol./1730.787 km] Berlin Hbf -> Mainz Hbf -> Saarbrücken Hbf -> Freiburg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 5 tours | 7213.764 km.