Evaluation function - canonical genetic algorithm:
However note that this termination check may be related or the same as the evaluation function - that discussed later - but it may be something entirely different to this. Hence there may not be a definitive answer to the problem you're looking on and it may only be possible to evolve solutions that are as good as possible. However in this case there it may not be obvious where to stop, and therefore it may be a good idea to produce as many populations as possible given the computing or time resources you have available. Thus in this case, the termination function may be a specific time limit or a justify number of generations. Rather than it is very important to notice that the best individual in your final population may not be as good as the best individual in a previous or earlier generation as GAs do not perform hill-climbing searches then it is perfectly possible for generations to degrade. Therefore GAs should record the best individuals from every generation and but as a final solution presented to the user their they should output the best solution found over all the generations.