The travelling salesman starts from the green city at the centre of the screen. He tries to find the shortest path that takes him to each of the red cities, without ever visiting the same city twice. In this example, the cities are arranged in a spiral.

The genetic algorithm uses a mating population of 400 chromosomes drawn from an initial population of 800 randomly generated chromosomes. The mutation rate/probability is 10% for each offspring (mutation is effected by swapping the positions of two cities in the chromosome sequence).

The parent chromosomes (each of length 30, i.e. the number of cities) are cut so that a section of length 6 is mixed to produce the two offspring.

Once a solution has been found, the applet generates a new set of cities, and the genetic algorithm begins a new search.

Thanks go to Andrew Gibson for pointing out an error in the previous version of the code.

 

The source.