Roulette Selection in Genetic Algorithms

后端 未结 14 1011
庸人自扰
庸人自扰 2020-11-27 12:19

Can anyone provide some pseudo code for a roulette selection function? How would I implement this:

14条回答
  •  我在风中等你
    2020-11-27 12:49

    From the above answer, I got the following, which was clearer to me than the answer itself.

    To give an example:

    Random(sum) :: Random(12) Iterating through the population, we check the following: random < sum

    Let us chose 7 as the random number.

    Index   |   Fitness |   Sum |   7 < Sum
    0       |   2   |   2       |   false
    1       |   3   |   5       |   false
    2       |   1   |   6       |   false
    3       |   4   |   10      |   true
    4       |   2   |   12      |   ...
    

    Through this example, the most fit (Index 3) has the highest percentage of being chosen (33%); as the random number only has to land within 6->10, and it will be chosen.

        for (unsigned int i=0;i

提交回复
热议问题