Search code examples
genetic-algorithmtraveling-salesman

Fitness function in genetic algorithm for the travelling salesman


I'm trying to write a genetic algorithm for the Travelling Salesman Problem (TSP). For selection I'm implementing Roulette Wheel Selection: http://www.edc.ncl.ac.uk/highlight/rhjanuary2007g02.php/

It basicaly means that the probability to be selected for mating is proportional to the value of the fitness function.
The most common fitness function for TSP is the length of the route. However, the 'shorter' the route is - the better.

How can I write a fitness function that will describe the shortness of the route?
Or how can I convert the true length of each route to a probability?


Solution

  • You have a cost function (the lower the better) that you want to convert to a fitness function (the higher the better).

    Use the inverse. If the cost (distance) is x then your fitness could become 1/x.