Optimizing Vehicle Routes with Genetic Algorithms
Delivery routing becomes difficult very quickly. A good plan has to serve every customer, stay within vehicle capacity, arrive inside each customer’s time window, and return every vehicle to the depot—while using as few vehicles and as little total distance as possible.
That is the Vehicle Routing Problem with Time Windows (VRPTW). I used a genetic algorithm (GA) to study two questions:
- Which evolutionary parameters work well for this constrained ordering problem?
- What changes when a single combined fitness score is replaced by a genuinely multi-objective ranking?
What a solution looks like
A solution is an ordered chromosome containing the customers. It has no route separators. The decoder walks through the sequence and starts a new vehicle whenever another customer would violate capacity or time-window constraints.
A chromosome is therefore an indirect representation:
The decoder turns that sequence into routes:
for customer in chromosome:
attempt to assign customer to current vehicle
if capacity or time window would be violated:
return current vehicle to the depot
create a new vehicle
else:
add customer to the current route
return all routes and their total distance
This representation is simple, but it creates an important requirement for the genetic operators: every offspring must still contain every customer exactly once.
The benchmark
The experiments used Solomon benchmark instances with 100 customers. Each instance defines:
- customer coordinates;
- demand;
- ready time and due date;
- service time;
- one depot;
- vehicle capacity.
The benchmark families exercise different geographical and scheduling characteristics:
- R: randomly distributed customers;
- C: clustered customers;
- RC: a mixture of random and clustered locations;
- 1-series: short scheduling horizons and tighter windows;
- 2-series: longer horizons that allow more customers per route.
The two objectives were kept explicit throughout:
- minimize the number of vehicles;
- minimize total route distance.
Operators that preserve a route permutation
I compared uniform order crossover (UOX) with cycle crossover. Both create new customer orders without duplicating or dropping a customer.
For example, a mask selects positions to preserve from one parent while the remaining customer identifiers are inserted from the other parent in order. Cycle crossover instead follows a cycle between matching gene values in the two parents and exchanges the remaining positions.
UOX was selected for the main experiments because its convergence was smoother, even though cycle crossover also continued to improve.
Mutation used inversion: select two positions and reverse the subsequence between them. A valid permutation remains valid after inversion, although the decoded routes can still become worse:
parent: 3 | 4 1 5 6 8 | 9 0 2 7
child: 3 | 8 6 5 1 4 | 9 0 2 7
Finding useful GA parameters
The first experiment varied crossover, mutation, population size, and elitism using weighted-sum fitness.
The baseline tests included:
- 30 runs per configuration;
- 300 generations;
- tournament selection of size 3;
- 100-customer chromosomes;
- population sizes of 50, 300, and 500;
- elitism sizes of 0, 5, and 10;
- 90% crossover and 10% mutation as the selected balance.
Using crossover without mutation produced steady progress. Mutation-only search converged quickly, but then flattened at a weaker result. The comparison supported a low mutation rate: enough to introduce disruption without repeatedly damaging useful routes.
A larger population improved the search:
Low elitism was more useful than a larger elite. Carrying too many unchanged solutions forward protected strong individuals but reduced the diversity available to the next generation:
The final parameter choice was UOX, inversion mutation, population 500, elitism 5, 90% crossover, and 10% mutation. Results kept improving near the end of 300 generations, so the second experiment extended the search to 400 generations.
Three ways to define fitness
The representation and constraints remained the same in the second experiment. Only the fitness strategy changed.
Weighted sum
Weighted sum compressed the two objectives into one score:
fitness = 1.0 × vehicle_count + 0.001 × route_distance
Lower values were preferred. The weights favoured fleet size and produced strong vehicle-count results, but selecting the coefficients was itself a design problem. A different choice could produce a different trade-off.
Pareto ranking
Pareto ranking kept vehicle count and distance separate. A solution was considered nondominated when no other candidate was at least as good in every objective and strictly better in one.
Solutions on the same Pareto rank were treated as equally fit even if one used fewer vehicles and another used a shorter route. This preserved multiple useful trade-offs instead of forcing one weighted preference.
Normalized sum of ranks
Normalized sum of ranks independently ranked each objective in the population and combined those ranks:
fitness = (vehicle_rank + distance_rank) / total_ranks
It removed the scale difference between objectives without forcing a coefficient such as 1.0 or 0.001.
What the results showed
Weighted sum was strongest when the primary goal was minimizing the number of vehicles. Pareto ranking and normalized sum of ranks usually found shorter routes, but often with an additional vehicle.
Representative route maps show how different fitness choices changed the resulting topology:
| Weighted sum: C102 | Pareto ranking: RC202 |
|---|---|
| Pareto ranking: R202 | Normalized sum of ranks: R103 |
|---|---|
Across the benchmark table, the multi-objective methods did not consistently beat weighted sum in vehicle count. Their advantage was choice: they exposed multiple viable vehicle-distance compromises rather than one score shaped by a particular weight.
For example:
- Weighted sum found 17 vehicles / 1605.57 distance on R101.
- Pareto results on RC101 found 16 vehicles / 1792.78 distance.
- Normalized ranks on R103 found 14 vehicles / 1463.18 distance in the vehicle-oriented selection.
Different benchmark families also responded differently. Clustered, random, and mixed topologies did not favour one universal parameter configuration, which reinforced the need for per-instance tuning.
What I would change next
The results suggest three main improvements:
- Use route-aware crossover. Uniform order crossover preserves permutation validity, but route crossover or best-cost route crossover can preserve useful route segments directly.
- Run longer. The fitness curves were still improving at the stopping point, especially on the longer-horizon instances.
- Add a local-search optimizer. A GA is effective at exploring route structures; a post-optimizer could refine promising routes without relying entirely on evolutionary operators.
The most important result was not that one fitness method won every benchmark. It was that the optimization goal shapes the population you get. Weighted sum is useful when the business priority can be expressed as coefficients. Pareto ranking and normalized ranks are more useful when decision-makers want to inspect a range of trade-offs between fleet size and travel cost.