
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
- Düsseldorf Hbf (90 vol.)
- Hannover Hbf (70 vol.)
- Aachen Hbf (95 vol.)
- Dresden Hbf (65 vol.)
- Hamburg Hbf (20 vol.)
- München Hbf (45 vol.)
- Bremen Hbf (75 vol.)
- Nürnberg Hbf (100 vol.)
- Ulm Hbf (25 vol.)
- Köln Hbf (80 vol.)
- Mannheim Hbf (45 vol.)
- Kiel Hbf (35 vol.)
- Mainz Hbf (95 vol.)
- Osnabrück Hbf (65 vol.)
- Freiburg Hbf (75 vol.)
Tour 1
COST: 1234.774 km
LOAD: 295 vol.
- Hamburg Hbf | 20 vol.
- Bremen Hbf | 75 vol.
- Osnabrück Hbf | 65 vol.
- Hannover Hbf | 70 vol.
- Dresden Hbf | 65 vol.
Tour 2
COST: 1586.636 km
LOAD: 300 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 80 vol.
- Düsseldorf Hbf | 90 vol.
- Kiel Hbf | 35 vol.
Tour 3
COST: 1871.998 km
LOAD: 285 vol.
- Mainz Hbf | 95 vol.
- Mannheim Hbf | 45 vol.
- Freiburg Hbf | 75 vol.
- Ulm Hbf | 25 vol.
- München Hbf | 45 vol.
Tour 4
COST: 869.684 km
LOAD: 100 vol.
- Nürnberg Hbf | 100 vol.

LOAD: 295 vol.
- Hamburg Hbf | 20 vol.
- Bremen Hbf | 75 vol.
- Osnabrück Hbf | 65 vol.
- Hannover Hbf | 70 vol.
- Dresden Hbf | 65 vol.

LOAD: 300 vol.
- Aachen Hbf | 95 vol.
- Köln Hbf | 80 vol.
- Düsseldorf Hbf | 90 vol.
- Kiel Hbf | 35 vol.

LOAD: 285 vol.
- Mainz Hbf | 95 vol.
- Mannheim Hbf | 45 vol.
- Freiburg Hbf | 75 vol.
- Ulm Hbf | 25 vol.
- München Hbf | 45 vol.

LOAD: 100 vol.
- Nürnberg Hbf | 100 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: 980 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 90, 0, 70, 95, 0, 65, 20, 45, 75, 0, 0, 100, 0, 25, 80, 45, 35, 95, 0, 0, 65, 75] ITERATION Generation: #1 Best cost: 6509.313 | Path: [1, 2, 16, 5, 15, 1, 7, 13, 9, 17, 8, 1, 4, 10, 22, 18, 1, 19, 23, 1] Best cost: 5873.920 | Path: [1, 13, 9, 15, 17, 23, 1, 7, 4, 10, 8, 18, 1, 22, 2, 16, 1, 19, 5, 1] Best cost: 5859.063 | Path: [1, 2, 16, 5, 8, 1, 7, 13, 9, 15, 17, 1, 4, 22, 10, 18, 1, 19, 23, 1] Best cost: 5848.907 | Path: [1, 5, 16, 2, 8, 1, 7, 13, 9, 15, 17, 1, 18, 10, 22, 4, 1, 19, 23, 1] Best cost: 5781.131 | Path: [1, 19, 17, 23, 15, 9, 1, 7, 10, 4, 22, 8, 1, 18, 2, 16, 5, 1, 13, 1] Best cost: 5761.720 | Path: [1, 13, 9, 15, 23, 17, 1, 7, 4, 10, 8, 18, 1, 22, 2, 16, 1, 5, 19, 1] Best cost: 5653.259 | Path: [1, 19, 17, 23, 15, 9, 1, 7, 4, 10, 22, 8, 1, 18, 2, 16, 5, 1, 13, 1] Generation: #6 Best cost: 5653.259 | Path: [1, 7, 4, 10, 22, 8, 1, 18, 2, 16, 5, 1, 19, 17, 23, 15, 9, 1, 13, 1] OPTIMIZING each tour... Current: [[1, 7, 4, 10, 22, 8, 1], [1, 18, 2, 16, 5, 1], [1, 19, 17, 23, 15, 9, 1], [1, 13, 1]] [1] Cost: 1324.222 to 1234.774 | Optimized: [1, 8, 10, 22, 4, 7, 1] [2] Cost: 1587.355 to 1586.636 | Optimized: [1, 5, 16, 2, 18, 1] ACO RESULTS [1/295 vol./1234.774 km] Berlin Hbf -> Hamburg Hbf -> Bremen Hbf -> Osnabrück Hbf -> Hannover Hbf -> Dresden Hbf --> Berlin Hbf [2/300 vol./1586.636 km] Berlin Hbf -> Aachen Hbf -> Köln Hbf -> Düsseldorf Hbf -> Kiel Hbf --> Berlin Hbf [3/285 vol./1871.998 km] Berlin Hbf -> Mainz Hbf -> Mannheim Hbf -> Freiburg Hbf -> Ulm Hbf -> München Hbf --> Berlin Hbf [4/100 vol./ 869.684 km] Berlin Hbf -> Nürnberg Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5563.092 km.