Combining Genetic Search and Simulated Annealing for CVRP
Genetic algorithms and simulated annealing solve search problems in different ways. A GA maintains a population and explores many structures in parallel. Simulated annealing follows one solution at a time and searches its neighbourhood.
I combined those strengths on the Capacitated Vehicle Routing Problem (CVRP):
- use a GA to decide how customers are grouped into vehicle routes;
- run simulated annealing (SA) on the routes of the best GA individual;
- return the refined individual to the GA population.
The goal was to improve route distance without losing the vehicle-count structure already discovered by the GA.
The routing problem
The CVRP has one depot, a set of customers with known demand, identical vehicles with fixed capacity, and two objectives:
- minimize the number of vehicles;
- minimize the total distance covered by all vehicles.
Every customer must be served exactly once, every route must start and end at the depot, and the demand on a route cannot exceed vehicle capacity.
As in the earlier routing experiments, the GA used an integer permutation for the chromosome. The depot was not stored in the chromosome. During decoding, the algorithm inserted a route boundary when adding the next customer would exceed capacity:
customers = 2 5 9 15 12 13 6 11 8 3 7 10 4 14 1
decoded:
depot → 2 5 9 15 12 → depot
depot → 13 6 11 8 3 → depot
depot → 7 10 4 14 1 → depot
Genetic search for vehicle grouping
The GA used:
- population size 4,000;
- 150 generations;
- tournament selection of size 3;
- 90% selection pressure;
- 90% uniform order crossover;
- 10% inversion mutation;
- 5 elites;
- generational replacement.
Its weighted-sum fitness strongly emphasized the number of vehicles:
fitness = 100 × vehicle_count + 0.001 × total_route_distance
The weighting made the GA’s role explicit: find a compact fleet arrangement first. Route distance was still evaluated, but vehicle count had much greater influence on selection.
The GA loop was:
population = random feasible permutations
evaluate(population)
for generation in 1..N:
next_population = []
while next_population is incomplete:
parents = tournament_select(population)
offspring = genetic_operator(parents)
append offspring to next_population
evaluate(next_population)
population = next_population
Uniform order crossover preserved the permutation, while inversion mutation reversed a subsequence. Infeasible offspring were repaired where possible; otherwise they received a poor fitness.
Simulated annealing as a route optimizer
Once the GA chose a best chromosome, each decoded route was passed independently to SA.
At a high level, SA evaluates a neighbouring route order and applies this rule:
delta = cost(neighbour) - cost(current)
if delta < 0:
accept neighbour
else if acceptance_probability(delta, temperature) > random(0, 1):
accept neighbour
temperature = cooling_factor × temperature
Accepting occasional worse moves is the useful part of simulated annealing. At a high temperature, the search can cross a local barrier. As the temperature decreases, acceptance becomes more conservative and the search settles around a promising region.
The project used:
- initial temperature: 0.99999;
- cooling factor: 0.1;
- 3 minutes of SA per route;
- the best GA individual of the current generation as input.
The hybrid loop
The hybrid strategy ran SA at the end of each GA generation:
for generation in 1..N:
evolve GA population
best = best_individual(population)
for route in decoded_routes(best):
route = simulated_annealing(route)
hybrid_best = reassemble best with optimized routes
insert hybrid_best into population
remove worst individual to preserve population size
Only the best GA individual was improved because SA was expensive: each decoded route received a three-minute search window, so running SA on the entire population would have greatly increased runtime.
The hybrid plot shows a rougher path than the GA-only plot. That is expected: the GA advances one best individual generation by generation, while SA periodically changes the route of that individual:
| GA route performance | Hybrid route after SA |
|---|---|
Results across CVRP instances
The hybrid strategy generally produced shorter routes than either method alone while keeping the same number of vehicles as GA or SA. Representative best results were:
| Dataset | Vehicles | Hybrid route | GA route | SA route |
|---|---|---|---|---|
eil22 |
4 | 374.97 | 479.28 | 776.48 |
eil30 |
3 | 504.76 | 601.97 | 858.52 |
eil33 |
4 | 866.09 | 981.65 | 1,267.26 |
eil51 |
5 | 555.74 | 623.01 | 1,146.39 |
eilA101 |
8 | 1,165.31 | 1,489.13 | 1,876.98 |
gil262 |
25 | 16,797.44 | 23,398.72 | 17,741.23 |
SA by itself preserved feasible routes and improved them locally, but it was less effective at discovering good fleet groupings. GA was more stable and better at the global vehicle-allocation part. The hybrid method combined those roles.
Route visualizations
The resulting route maps make the difference between a good global grouping and local route refinement visible:
Hybrid: eil33 |
Hybrid: eil51 |
|---|---|
Hybrid: att48 |
Hybrid: eilA101 |
|---|---|
Statistical result
The hybrid method had the best mean route in the 13-instance comparison, but the result did not cross the 95% significance threshold.
Comparing hybrid with GA:
- hybrid mean: 5,290.80
- GA mean: 6,425.27
- t statistic: -0.2267
- two-tailed p-value: 0.8226
Comparing hybrid with SA:
- hybrid mean: 5,290.80
- SA mean: 9,538.29
- t statistic: -0.5794
- two-tailed p-value: 0.5699
The correct interpretation is not that the hybrid approach was proven superior. It was better in the observed runs, but the sample did not provide enough evidence to reject the null hypothesis.
Why the hybrid worked in practice
The two methods addressed different parts of the CVRP:
- GA explored the broad arrangement of customers and vehicle groups.
- SA focused on the local ordering inside one route.
That division of labour matters. A route can be badly ordered even when the customer grouping is good. Similarly, a locally polished route can still be part of a poor fleet allocation.
The project suggested a further improvement: apply SA to several strong GA individuals rather than only the best one. That would be more computationally expensive, but it could allow the GA population to receive a wider range of refined structures and converge faster.
Takeaway
Hybridization did not remove the need to tune either algorithm. It changed the role of each one:
- GA: global structure and fleet count;
- SA: local route refinement;
- Hybrid loop: transfer improved routes back into the evolving population.
For this CVRP study, that combination produced consistently better observed routes than either method alone, while the statistical result correctly reminded us that a promising engineering improvement still needs stronger evidence before it can be called a general advantage.