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: 16 customers
- Hannover Hbf (65 vol.)
- Aachen Hbf (95 vol.)
- Dresden Hbf (50 vol.)
- München Hbf (85 vol.)
- Dortmund Hbf (50 vol.)
- Nürnberg Hbf (95 vol.)
- Karlsruhe Hbf (20 vol.)
- Ulm Hbf (60 vol.)
- Köln Hbf (75 vol.)
- Mannheim Hbf (55 vol.)
- Kiel Hbf (75 vol.)
- Mainz Hbf (55 vol.)
- Würzburg Hbf (65 vol.)
- Saarbrücken Hbf (60 vol.)
- Osnabrück Hbf (50 vol.)
- Freiburg Hbf (80 vol.)
Tour 1
COST: 1749.349 km
LOAD: 270 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 20 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 60 vol.
- Mainz Hbf | 55 vol.
Tour 2
COST: 1436.917 km
LOAD: 290 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 60 vol.
- Nürnberg Hbf | 95 vol.
- Dresden Hbf | 50 vol.
Tour 3
COST: 1334.929 km
LOAD: 240 vol.
- Hannover Hbf | 65 vol.
- Osnabrück Hbf | 50 vol.
- Dortmund Hbf | 50 vol.
- Kiel Hbf | 75 vol.
Tour 4
COST: 1488.486 km
LOAD: 235 vol.
- Würzburg Hbf | 65 vol.
- Köln Hbf | 75 vol.
- Aachen Hbf | 95 vol.
LOAD: 270 vol.
- Mannheim Hbf | 55 vol.
- Karlsruhe Hbf | 20 vol.
- Freiburg Hbf | 80 vol.
- Saarbrücken Hbf | 60 vol.
- Mainz Hbf | 55 vol.
LOAD: 290 vol.
- München Hbf | 85 vol.
- Ulm Hbf | 60 vol.
- Nürnberg Hbf | 95 vol.
- Dresden Hbf | 50 vol.
LOAD: 240 vol.
- Hannover Hbf | 65 vol.
- Osnabrück Hbf | 50 vol.
- Dortmund Hbf | 50 vol.
- Kiel Hbf | 75 vol.
LOAD: 235 vol.
- Würzburg Hbf | 65 vol.
- Köln Hbf | 75 vol.
- Aachen 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: 1035 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 0, 0, 65, 95, 0, 50, 0, 85, 0, 0, 50, 95, 20, 60, 75, 55, 75, 55, 65, 60, 50, 80] ITERATION Generation: #1 Best cost: 6879.885 | Path: [1, 4, 22, 12, 16, 19, 1, 7, 20, 13, 9, 1, 18, 14, 17, 21, 23, 1, 15, 5, 1] Best cost: 6827.640 | Path: [1, 9, 13, 20, 19, 1, 7, 15, 14, 17, 21, 12, 1, 4, 22, 16, 5, 1, 18, 23, 1] Best cost: 6649.900 | Path: [1, 14, 17, 19, 16, 5, 1, 7, 18, 4, 22, 12, 1, 20, 13, 9, 1, 15, 23, 21, 1] Best cost: 6635.467 | Path: [1, 18, 4, 22, 12, 19, 1, 7, 20, 13, 9, 1, 5, 16, 17, 14, 1, 21, 23, 15, 1] Best cost: 6608.226 | Path: [1, 19, 17, 14, 23, 21, 1, 7, 13, 20, 15, 1, 4, 22, 12, 16, 1, 18, 5, 9, 1] Best cost: 6388.095 | Path: [1, 21, 14, 17, 19, 20, 1, 7, 13, 9, 15, 1, 18, 4, 22, 12, 1, 16, 5, 23, 1] Best cost: 6371.832 | Path: [1, 9, 15, 14, 17, 19, 1, 7, 13, 20, 4, 1, 22, 12, 16, 5, 1, 18, 21, 23, 1] Best cost: 6359.129 | Path: [1, 23, 14, 17, 19, 20, 1, 7, 13, 9, 15, 1, 4, 22, 12, 16, 21, 1, 18, 5, 1] Best cost: 6353.313 | Path: [1, 20, 19, 17, 14, 23, 1, 7, 13, 9, 15, 1, 4, 22, 12, 16, 21, 1, 18, 5, 1] Best cost: 6324.322 | Path: [1, 19, 17, 14, 23, 21, 1, 7, 9, 15, 20, 1, 4, 22, 12, 16, 1, 18, 5, 13, 1] Generation: #2 Best cost: 6188.874 | Path: [1, 18, 4, 22, 12, 19, 1, 7, 13, 9, 15, 1, 20, 17, 14, 23, 21, 1, 16, 5, 1] Generation: #3 Best cost: 6046.062 | Path: [1, 17, 14, 23, 21, 19, 1, 7, 13, 9, 15, 1, 18, 4, 22, 12, 1, 20, 16, 5, 1] OPTIMIZING each tour... Current: [[1, 17, 14, 23, 21, 19, 1], [1, 7, 13, 9, 15, 1], [1, 18, 4, 22, 12, 1], [1, 20, 16, 5, 1]] [2] Cost: 1445.364 to 1436.917 | Optimized: [1, 9, 15, 13, 7, 1] [3] Cost: 1362.863 to 1334.929 | Optimized: [1, 4, 22, 12, 18, 1] ACO RESULTS [1/270 vol./1749.349 km] Berlin Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Saarbrücken Hbf -> Mainz Hbf --> Berlin Hbf [2/290 vol./1436.917 km] Berlin Hbf -> München Hbf -> Ulm Hbf -> Nürnberg Hbf -> Dresden Hbf --> Berlin Hbf [3/240 vol./1334.929 km] Berlin Hbf -> Hannover Hbf -> Osnabrück Hbf -> Dortmund Hbf -> Kiel Hbf --> Berlin Hbf [4/235 vol./1488.486 km] Berlin Hbf -> Würzburg Hbf -> Köln Hbf -> Aachen Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 6009.681 km.