algorithmgenetic-algorithmgenetic-programmingroulette-wheel-selection

Genetic Algorithms : Roulette wheel selection


I'm trying to implement roulette wheel selection. I found some pseudocode and I have implemented it however, there is something I dont understand regarding the genomes of 0 fitness.

the psudocode I found was this

for each genome in population:
    totalFitness = totalFitness + genome.fitness

x = random(0, totalFitness) 

currentCount = 0

for each genome in population:
    currentCount = currentCount + genome.fitness
    if currentCount >= x:
        parent = genome
        break

My concern is the following: say I have 5 genomes, which score the following fitness

G1 = 11
G2 = 0
G3 = 0
G4 = 0
G5 = 0

Based on the algorithm above, surely only G1 could ever be selected which would kill the genetic diversity.... Have I understood this right?


Solution

  • Yes, you have understood correctly. If you want to have a better diversity you should give partial credit to the individuals, not just zero when they aren't very good.

    One easy way to achieve this is by counting errors of the individual and then let the fitness be 1/(1+Errors). But just finding a way to give your individuals some points would solve your problem.

    You may also want to look into scaling the fitness values. Now the chance of selection is proportional to the fitness.