pythongenetic-algorithmpython-2.xroulette-wheel-selection

Genetic Algorithm roulette selection - returning 2 parent chromosomes


I want to implement roulette wheel selection in my GA algorithm. I tried following guide https://stackoverflow.com/a/5315710/536474 but it sends back the new population instead of 2 best parents. Suppose I already found fitness score for the initial population and now I need to select two parent chromosomes for a population according to their fitness. And further it goes for crossover and mutation processes. In the following case, how can I find 2 best parents for crossover based on roulette wheel selection?

population = [[text1],[text2],[text3],.....[textnum]]
fitnesses = [0.8057515980834005, 1.2151126619653638, 0.6429369518995411, ... 0.805412427797966]
num = 50

Solution

  • It doesn't send back a new population, just num parents. If you want 2 parents call roulette_select this way:

    roulette_select(population, fitnesses, 2)
    

    Often GA crossover operator expects two parents but there are variations with many parents (e.g. Genetic algorithms with multi-parent recombination - A.E. Eiben, P-E. Raué, Zs. Ruttkay).

    There are also self-crossover operators.

    So having a num input parameters makes sense.