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 (60 vol.)
- Düsseldorf Hbf (90 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (65 vol.)
- Bremen Hbf (25 vol.)
- Leipzig Hbf (25 vol.)
- Dortmund Hbf (90 vol.)
- Nürnberg Hbf (75 vol.)
- Karlsruhe Hbf (25 vol.)
- Ulm Hbf (20 vol.)
- Köln Hbf (45 vol.)
- Kiel Hbf (75 vol.)
- Mainz Hbf (100 vol.)
- Würzburg Hbf (20 vol.)
- Freiburg Hbf (30 vol.)
Tour 1
COST: 1420.058 km
LOAD: 300 vol.
- Dortmund Hbf | 90 vol.
- Düsseldorf Hbf | 90 vol.
- Bremen Hbf | 25 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 75 vol.
Tour 2
COST: 1872.66 km
LOAD: 260 vol.
- Leipzig Hbf | 25 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 20 vol.
- Karlsruhe Hbf | 25 vol.
- Freiburg Hbf | 30 vol.
- Würzburg Hbf | 20 vol.
Tour 3
COST: 1369.425 km
LOAD: 205 vol.
- Köln Hbf | 45 vol.
- Mainz Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 60 vol.
LOAD: 300 vol.
- Dortmund Hbf | 90 vol.
- Düsseldorf Hbf | 90 vol.
- Bremen Hbf | 25 vol.
- Hamburg Hbf | 20 vol.
- Kiel Hbf | 75 vol.
LOAD: 260 vol.
- Leipzig Hbf | 25 vol.
- Nürnberg Hbf | 75 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 20 vol.
- Karlsruhe Hbf | 25 vol.
- Freiburg Hbf | 30 vol.
- Würzburg Hbf | 20 vol.
LOAD: 205 vol.
- Köln Hbf | 45 vol.
- Mainz Hbf | 100 vol.
- Kassel-Wilhelmshöhe | 60 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: 765 vol. | Vehicle capacity: 300 vol. Loads: [60, 0, 90, 0, 0, 0, 0, 0, 20, 65, 25, 25, 90, 75, 25, 20, 45, 0, 75, 100, 20, 0, 0, 30] ITERATION Generation: #1 Best cost: 5328.394 | Path: [1, 0, 20, 13, 9, 15, 14, 23, 1, 11, 10, 8, 18, 12, 16, 1, 2, 19, 1] Best cost: 5095.783 | Path: [1, 2, 16, 12, 0, 1, 11, 13, 20, 19, 14, 23, 15, 1, 8, 18, 10, 9, 1] Best cost: 4861.224 | Path: [1, 8, 18, 10, 12, 2, 1, 11, 20, 13, 9, 15, 14, 23, 1, 0, 16, 19, 1] Best cost: 4848.935 | Path: [1, 9, 15, 14, 23, 19, 20, 11, 1, 8, 18, 10, 2, 16, 1, 13, 0, 12, 1] Best cost: 4760.508 | Path: [1, 14, 23, 19, 16, 2, 1, 11, 0, 12, 10, 8, 18, 1, 13, 20, 15, 9, 1] Generation: #2 Best cost: 4704.674 | Path: [1, 8, 18, 10, 12, 2, 1, 11, 13, 9, 15, 14, 23, 20, 1, 0, 16, 19, 1] OPTIMIZING each tour... Current: [[1, 8, 18, 10, 12, 2, 1], [1, 11, 13, 9, 15, 14, 23, 20, 1], [1, 0, 16, 19, 1]] [1] Cost: 1447.901 to 1420.058 | Optimized: [1, 12, 2, 10, 8, 18, 1] [3] Cost: 1384.113 to 1369.425 | Optimized: [1, 16, 19, 0, 1] ACO RESULTS [1/300 vol./1420.058 km] Berlin Hbf -> Dortmund Hbf -> Düsseldorf Hbf -> Bremen Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [2/260 vol./1872.660 km] Berlin Hbf -> Leipzig Hbf -> Nürnberg Hbf -> München Hbf -> Ulm Hbf -> Karlsruhe Hbf -> Freiburg Hbf -> Würzburg Hbf --> Berlin Hbf [3/205 vol./1369.425 km] Berlin Hbf -> Köln Hbf -> Mainz Hbf -> Kassel-Wilhelmshöhe --> Berlin Hbf OPTIMIZATION RESULT: 3 tours | 4662.143 km.