Search code examples
algorithmgenetic-algorithmgenetic-programming

Roulette Wheel Selection in genetic algorithm


I am confusing the roulette wheel selection in genetic algorithm. The algorithm is shown as following

for i=1 to N
 x=random[0,1];
 k=1;
 while k<N&&x>cusum
   k=k+1
 end
tmp_P[i]=P[k];
end

Is it correct? I am confusing the while condition

First way:

 while k<N&&x>cusum
   k=k+1
 end
 tmp_P[i]=P[k];

Or second way

 while k<N&&x>cusum
   k=k+1;     
   tmp_P[i]=P[k];
end

Which is correct? Thank you so much


Solution

  • The first way is correct.

    You go through your cumsum array until you find the one bigger than your random number and select that individual.

    However, I would expect that your cusum variable should be an array and you would use:

     while k<N && x>cusum[k]