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