Reference: http://blog.sina.com.cn/s/blog_67c17d1c01017hyt.html
1. Basic idea: The probability of an individual being selected is proportional to the value of its fitness function
If the population size is n and the fitness of individual i is fi, then the probability of individual I being selected to inherit into the next generation group is:
2. Working process:
It is assumed that the appropriateness score of all individuals in a group is represented by a pie chart (see figure).
Each chromosome in a group specifies a small chunk in the pie chart. The size of the block is proportional to the adaptive fraction of the chromosome, and the higher the adaptability score, the larger the size of the corresponding small block in the pie chart. In order to pick a chromosome, the thing to do is to rotate the wheel until the wheel stops, to see which piece the pointer stops on, and select the chromosome that corresponds to it.
If the resulting random number is 0.81, then the individual of number 6th is selected.
From this we can see:
1. Roulette algorithm is related to the order of individual;
C + + implementation:
introulettewheelselection () {Srand (0);//define RAND to trigger a random worthwhile initial value DoubleM=rand ()/Double(Rand_max);//produces a random value of [0,1]; intProbability_total=0; intselection=0 for(intI=0; i<size;i++) //size is the number of individual sizes {probability_total=probability_total+Probability[i]; if(probability_total>=m) {Selection=i; Break; } returnSelection;}
The algorithm and realization of roulette betting