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
- Frankfurt Hbf (55 vol.)
- Hannover Hbf (65 vol.)
- Aachen Hbf (70 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (35 vol.)
- Hamburg Hbf (65 vol.)
- München Hbf (70 vol.)
- Leipzig Hbf (55 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (60 vol.)
- Karlsruhe Hbf (80 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (60 vol.)
- Würzburg Hbf (80 vol.)
- Freiburg Hbf (85 vol.)
Tour 1
COST: 1470.411 km
LOAD: 275 vol.
- Dortmund Hbf | 90 vol.
- Aachen Hbf | 70 vol.
- Mainz Hbf | 60 vol.
- Frankfurt Hbf | 55 vol.
Tour 2
COST: 1174.141 km
LOAD: 255 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 55 vol.
- Hannover Hbf | 65 vol.
- Hamburg Hbf | 65 vol.
- Kiel Hbf | 35 vol.
Tour 3
COST: 1645.527 km
LOAD: 260 vol.
- Stuttgart Hbf | 95 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 85 vol.
Tour 4
COST: 1345.202 km
LOAD: 210 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 70 vol.
LOAD: 275 vol.
- Dortmund Hbf | 90 vol.
- Aachen Hbf | 70 vol.
- Mainz Hbf | 60 vol.
- Frankfurt Hbf | 55 vol.
LOAD: 255 vol.
- Dresden Hbf | 35 vol.
- Leipzig Hbf | 55 vol.
- Hannover Hbf | 65 vol.
- Hamburg Hbf | 65 vol.
- Kiel Hbf | 35 vol.
LOAD: 260 vol.
- Stuttgart Hbf | 95 vol.
- Karlsruhe Hbf | 80 vol.
- Freiburg Hbf | 85 vol.
LOAD: 210 vol.
- Würzburg Hbf | 80 vol.
- Nürnberg Hbf | 60 vol.
- München Hbf | 70 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: 1000 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 0, 55, 65, 70, 95, 35, 65, 70, 0, 55, 90, 60, 80, 0, 0, 0, 35, 60, 80, 0, 0, 85] ITERATION Generation: #1 Best cost: 6613.364 | Path: [1, 3, 19, 20, 13, 7, 1, 11, 4, 8, 18, 5, 1, 12, 14, 6, 1, 9, 23, 1] Best cost: 6461.642 | Path: [1, 4, 8, 18, 12, 7, 1, 11, 13, 20, 3, 1, 19, 14, 6, 1, 9, 23, 5, 1] Best cost: 6455.028 | Path: [1, 5, 12, 4, 8, 1, 11, 7, 13, 20, 3, 1, 18, 19, 14, 6, 1, 9, 23, 1] Best cost: 6215.959 | Path: [1, 6, 14, 23, 7, 1, 11, 4, 8, 18, 5, 1, 20, 3, 19, 12, 1, 13, 9, 1] Best cost: 6091.388 | Path: [1, 8, 18, 4, 7, 11, 1, 13, 20, 3, 19, 1, 12, 5, 14, 1, 6, 23, 9, 1] Best cost: 5996.639 | Path: [1, 12, 5, 19, 3, 1, 7, 11, 4, 8, 18, 1, 20, 13, 9, 14, 1, 6, 23, 1] Best cost: 5817.688 | Path: [1, 7, 11, 4, 8, 18, 1, 12, 5, 3, 19, 1, 13, 20, 6, 1, 9, 14, 23, 1] Best cost: 5782.642 | Path: [1, 18, 8, 4, 11, 7, 1, 12, 5, 19, 3, 1, 13, 20, 6, 1, 9, 14, 23, 1] Best cost: 5772.246 | Path: [1, 12, 5, 19, 3, 1, 7, 11, 4, 8, 18, 1, 13, 20, 6, 1, 9, 14, 23, 1] Best cost: 5704.782 | Path: [1, 12, 5, 19, 3, 1, 7, 11, 4, 8, 18, 1, 6, 14, 23, 1, 13, 20, 9, 1] OPTIMIZING each tour... Current: [[1, 12, 5, 19, 3, 1], [1, 7, 11, 4, 8, 18, 1], [1, 6, 14, 23, 1], [1, 13, 20, 9, 1]] [4] Cost: 1414.703 to 1345.202 | Optimized: [1, 20, 13, 9, 1] ACO RESULTS [1/275 vol./1470.411 km] Berlin Hbf -> Dortmund Hbf -> Aachen Hbf -> Mainz Hbf -> Frankfurt Hbf --> Berlin Hbf [2/255 vol./1174.141 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hannover Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/260 vol./1645.527 km] Berlin Hbf -> Stuttgart Hbf -> Karlsruhe Hbf -> Freiburg Hbf --> Berlin Hbf [4/210 vol./1345.202 km] Berlin Hbf -> Würzburg Hbf -> Nürnberg Hbf -> München Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5635.281 km.