4 minute read

The Traveling Salesman Problem (TSP) is a useful stress test for search algorithms. Every city must be visited exactly once, and the route must return to its starting point. The objective sounds simple—minimize the tour length—but the number of possible permutations grows extremely quickly.

I compared two population-based meta-heuristics on the same TSPLIB instances:

  • a genetic algorithm (GA) that evolves permutations of cities;
  • ant colony optimization (ACO), where artificial ants construct tours using pheromone and distance information.

The aim was not to declare a universal winner. It was to see how each method behaved as the size and structure of the TSP changed.

The shared problem

A TSP route can be represented as a Hamiltonian cycle. For the GA, a chromosome is simply a permutation of the city identifiers:

0 3 4 7 5 8 9 6 1 2

Example decoded Traveling Salesman tour

Fitness was the total Euclidean distance of the closed route. Lower values were better. A candidate was invalid if a city appeared more than once or was omitted.

The comparison covered 13 symmetric TSPLIB instances ranging from 70 to 535 cities:

a280, bier127, eil76, kroA100, kroA200, kroB150,
kroD100, lin105, lin318, st70, ts225, att532, ali535

The genetic algorithm

The GA configuration was based on earlier permutation-problem experiments:

  • 30 runs per dataset;
  • population size 2,000;
  • 200 generations;
  • tournament selection of size 3;
  • 90% selection pressure;
  • 90% uniform order crossover;
  • 10% inversion mutation;
  • generational replacement;
  • 5 elites.

At each generation, parents were selected, operators created a new population, and the individuals were evaluated by route distance:

population = random permutations of all cities

repeat for each generation:
    next_population = []

    while next_population is not full:
        parent_a, parent_b = tournament_select(population)
        child_a, child_b = uniform_order_crossover(parent_a, parent_b)
        child_a = inversion_mutation(child_a, probability=0.1)
        add child_a and child_b to next_population

    preserve 5 elite individuals
    evaluate every route in next_population
    population = next_population

The run logs recorded generation-by-generation best and mean route lengths. For example, the st70 GA output continued improving over the 200 generations:

200  0  707.53187  1  707.53187
200  0  715.62906  1  715.62906
200  0  858.59205  1  864.47843
200  0  709.25061  1  709.25061
...
200  0  683.55546  1  683.55546

The convergence plot showed that the GA was still improving near the stopping point:

GA convergence across TSPLIB instances

Ant colony optimization

ACO constructs routes edge by edge. Each artificial ant maintains a list of visited cities and probabilistically selects the next city using two signals:

  • pheromone, learned from previously successful tours;
  • visibility, defined as the reciprocal of edge distance.

Ant foraging behavior: shorter paths attract more pheromone

The transition preference was:

score(edge) = pheromone(edge)^alpha × visibility(edge)^beta
visibility(edge) = 1 / distance(edge)

An ant selected among unvisited cities in proportion to these scores. After ants completed tours, pheromone on each edge was updated and allowed to evaporate:

pheromone = (1 - evaporation) × pheromone
pheromone += Q / tour_length

The experiment used:

alpha = -0.2
beta = 9.6
Q = 0.0001
pheromone persistence = 0.3
initial pheromone = 0.8

The ACO run output contained a final route length for each experiment. For st70, the best recorded ACO result was 715.53, while its best overall result in the report was 715.52975.

Results across problem sizes

On the small instances, the two algorithms were relatively close. GA produced the best observed route on st70: 683.56 versus ACO’s 715.53. On eil76, the best routes were 566.42 for GA and 563.06 for ACO.

As the number of cities increased, the gap widened. Representative results were:

Dataset Cities GA best ACO best Known optimum
eil76 76 566.42 563.06 538
kroA100 100 29,512.51 22,763.47 21,282
lin105 105 20,480.12 14,937.41 14,379
ts225 225 603,722.34 131,299.68 126,643
lin318 318 214,107.66 46,691.83 42,029
ali535 535 1,870,163.75 244,966.29 202,339

The GA route on the 70-city instance still looks compact and coherent:

GA route for the st70 instance

It also produced a plausible route for eil76:

GA route for the eil76 instance

ACO maintained route quality at much larger scales:

ACO route for the ali535 instance

ACO route for the lin318 instance

The report’s results show the main scaling difference: the GA continued to improve, but 2,000 individuals and 200 generations were not enough to keep pace with ACO on the largest instances.

Other ACO solutions

The ACO implementation remained close to the known optimum on several medium and large instances:

ACO route example Instance
ACO route for kroD100 kroD100
ACO route for lin105 lin105
ACO route for ts225 ts225

The colony’s edge-by-edge construction gives it a strong fit for graph problems. Pheromone accumulates where the partial route history supports short tours, while visibility supplies local distance knowledge immediately.

What the statistical test actually showed

A one-tailed t-test compared the best results from GA and ACO:

  • t statistic: 1.7227
  • p-value: 0.0553
  • critical value at 95%: 1.7823
  • critical value at 90%: 1.3562

The result was significant at the 90% level but not at the preferred 95% level. The careful interpretation is therefore important: ACO’s observed routes were consistently better in this experiment, but the small set of benchmark means did not cross the 95% threshold.

What I took away

The comparison showed three useful patterns:

  1. GA worked well on smaller instances. Its permutation representation and crossover operators found good routes without premature convergence.
  2. ACO scaled better on the larger graphs. Pheromone-guided construction made direct use of the edge structure of the TSP.
  3. More parameters are not the same as a better-fitted algorithm. Larger GA populations or more generations might have closed the gap, but ACO was already aligned with the graph-search nature of the problem.

The results also point toward hybridization. A GA could remain responsible for exploring global route structures while a 2-opt or 3-opt local search refines promising tours. Similarly, ACO could combine global pheromone learning with explicit local improvement.

The practical lesson is the same one that appears throughout evolutionary and swarm computing: the best result depends not only on how powerful the algorithm is, but also on how well its representation and operators match the problem.