%% This function creates Roulette Wheel Selection |
function choice = RouletteWheelSelection(weights) |
accumulation = cumsum(weights); |
p = rand() * accumulation(end); |
chosen_index = −1; |
for index = 1:length(accumulation) |
if (accumulation(index) > p) |
chosen_index = index; |
break; |
end |
end |
choice = chosen_index; |