The population does not need to be sorted at all - the key to choosing roulette is that the likelihood that a given person will be selected to play will be proportional to his suitability.
Say you have an unsortable population, with activities as follows:
[12, 45, 76, 32, 54, 21]
, 0 240 ( ). , , , . , , 112, :
Step 1: 112 - 12 = 100. This is > 0, so continue.
Step 2: 100 - 45 = 55. This is > 0, so continue.
Step 3: 55 - 76 = -21. This is <= 0, so stop.
, № 3 . , .
, :
let s = sum of population fitness
let r = random number in range [0, s].
let i = 0.
while r > 0 do:
r = r - fitness of individual #i
increment i
select individual #i - 1 for reproduction.
, - 1 - increment i, ( , , ).