Genetic Algorithm - Premature Convergence

I am trying to implement a Genetic Algorithm that solves a TSP. It works fine with a TSP of a small number of cities (say 10) and produces the optimal solution. However, when the number of cities is increased even to 50 cities, it converges prematurely. I tried changing the parameters (mutation prob, crossover prob, initial population size, number of generation), however it still does not converge to the optimal solution.

The algorithm I have implement is as following:

Create an initial population randomly of size p
Calculate the fitness 
Pick p/2 random individuals to the parents
While counter < p/2
     pick parent1 and parent2 by tournament selection
     child1, child2 = mutate and crossover parent1 and parent2
     add child1 and child2 to new population
pick p/2 distinct individuals from initial population and store in new population

Could any one tell me what I am doing wrong please?

1 answer

  • answered 2018-03-13 21:42 Carcigenicate

    Usually, you'll want to adjust the mutation rate over the course of the evolution, which I don't see you doing here.

    Start with a high mutation to give it a chance to find a few possible "evolution paths" (although what's considered high will depend on the application, you'll need to play around), then have the mutation decrease over time to prevent sporadic changes from hindering progress.

    You could make the mutation rate a function of the current generation, the current error, or both.

    But as the commentor mentioned, GAs are in no way guaranteed to give you optimal results. They usually give you "acceptable" results when dealing with a giant solution space.