The algorithm and realization of roulette betting

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.