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 (70 vol.)
- Frankfurt Hbf (45 vol.)
- Aachen Hbf (30 vol.)
- Stuttgart Hbf (95 vol.)
- Dresden Hbf (95 vol.)
- Hamburg Hbf (85 vol.)
- München Hbf (65 vol.)
- Leipzig Hbf (75 vol.)
- Dortmund Hbf (95 vol.)
- Karlsruhe Hbf (50 vol.)
- Ulm Hbf (85 vol.)
- Köln Hbf (55 vol.)
- Mannheim Hbf (40 vol.)
- Kiel Hbf (45 vol.)
- Würzburg Hbf (45 vol.)
Tour 1
COST: 1401.389 km
LOAD: 275 vol.
- Frankfurt Hbf | 45 vol.
- Mannheim Hbf | 40 vol.
- Karlsruhe Hbf | 50 vol.
- Stuttgart Hbf | 95 vol.
- Würzburg Hbf | 45 vol.
Tour 2
COST: 1165.88 km
LOAD: 300 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 75 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 45 vol.
Tour 3
COST: 1291.407 km
LOAD: 250 vol.
- Köln Hbf | 55 vol.
- Aachen Hbf | 30 vol.
- Düsseldorf Hbf | 70 vol.
- Dortmund Hbf | 95 vol.
Tour 4
COST: 1346.514 km
LOAD: 150 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 85 vol.
LOAD: 275 vol.
- Frankfurt Hbf | 45 vol.
- Mannheim Hbf | 40 vol.
- Karlsruhe Hbf | 50 vol.
- Stuttgart Hbf | 95 vol.
- Würzburg Hbf | 45 vol.
LOAD: 300 vol.
- Dresden Hbf | 95 vol.
- Leipzig Hbf | 75 vol.
- Hamburg Hbf | 85 vol.
- Kiel Hbf | 45 vol.
LOAD: 250 vol.
- Köln Hbf | 55 vol.
- Aachen Hbf | 30 vol.
- Düsseldorf Hbf | 70 vol.
- Dortmund Hbf | 95 vol.
LOAD: 150 vol.
- München Hbf | 65 vol.
- Ulm Hbf | 85 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: 975 vol. | Vehicle capacity: 300 vol. Loads: [0, 0, 70, 45, 0, 30, 95, 95, 85, 65, 0, 75, 95, 0, 50, 85, 55, 40, 45, 0, 45, 0, 0, 0] ITERATION Generation: #1 Best cost: 6479.915 | Path: [1, 2, 16, 5, 12, 3, 1, 7, 11, 20, 17, 18, 1, 8, 14, 6, 9, 1, 15, 1] Best cost: 6307.342 | Path: [1, 5, 16, 2, 12, 3, 1, 11, 7, 20, 14, 1, 8, 18, 17, 6, 1, 15, 9, 1] Best cost: 6032.274 | Path: [1, 7, 11, 20, 3, 17, 1, 8, 18, 12, 2, 1, 16, 5, 14, 6, 9, 1, 15, 1] Best cost: 5734.898 | Path: [1, 8, 18, 2, 16, 5, 1, 7, 11, 20, 3, 17, 1, 15, 6, 14, 9, 1, 12, 1] Best cost: 5547.703 | Path: [1, 14, 17, 3, 20, 6, 1, 7, 11, 8, 18, 1, 12, 2, 16, 5, 1, 9, 15, 1] Best cost: 5316.819 | Path: [1, 20, 3, 17, 14, 6, 1, 7, 11, 18, 8, 1, 12, 2, 16, 5, 1, 9, 15, 1] Best cost: 5232.298 | Path: [1, 3, 17, 14, 6, 20, 1, 7, 11, 8, 18, 1, 2, 16, 5, 12, 1, 9, 15, 1] Best cost: 5222.211 | Path: [1, 3, 17, 14, 6, 20, 1, 7, 11, 8, 18, 1, 12, 2, 16, 5, 1, 9, 15, 1] OPTIMIZING each tour... Current: [[1, 3, 17, 14, 6, 20, 1], [1, 7, 11, 8, 18, 1], [1, 12, 2, 16, 5, 1], [1, 9, 15, 1]] [3] Cost: 1308.428 to 1291.407 | Optimized: [1, 16, 5, 2, 12, 1] ACO RESULTS [1/275 vol./1401.389 km] Berlin Hbf -> Frankfurt Hbf -> Mannheim Hbf -> Karlsruhe Hbf -> Stuttgart Hbf -> Würzburg Hbf --> Berlin Hbf [2/300 vol./1165.880 km] Berlin Hbf -> Dresden Hbf -> Leipzig Hbf -> Hamburg Hbf -> Kiel Hbf --> Berlin Hbf [3/250 vol./1291.407 km] Berlin Hbf -> Köln Hbf -> Aachen Hbf -> Düsseldorf Hbf -> Dortmund Hbf --> Berlin Hbf [4/150 vol./1346.514 km] Berlin Hbf -> München Hbf -> Ulm Hbf --> Berlin Hbf OPTIMIZATION RESULT: 4 tours | 5205.190 km.