I am trying to implement a roulette wheel selection. I have understood this algorithm:
What I don't understand is how this corresponds to doing this instead: Roulette wheel selection algorithm (the answer with 44 votes). This makes sense to me, but not the one above.
The following is done using the sum
def choose_parent_using_RWS(genes, S, points):
P = randint(0, int(S))
for x in genes:
P += evaluate(x, points)
if P > S:
return x
return genes[-1]
the following is done by normalizing between 0 and 1
def choose_parent_using_RWS(genes, S, points):
P = randint(0, int(S))/S
for x in genes:
P += evaluate(x, points)/S
if P > S/S:
return x
return genes[-1]