Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reproduct(){
- var pais = [];
- var sum = 0;
- var probability = 0;
- var sumProb = 0;
- var x =0;
- for(var i = 0; i < joaninhas.length; i++){//for all members of population
- sum += joaninhas[i].score;//sum += fitness of this individual
- }// end for
- for(var i = 0; i < joaninhas.length; i++){//for all members of population
- probability = sumProb + (joaninhas[i].score/sum)//probability = sum of probabilities + (fitness / sum)
- sumProb += probability;//sum of probabilities += probability
- }//end for
- while(){//loop until new population is full
- x = 0;
- while(x < 2){//do this twice
- number = random(0,1);//number = Random between 0 and 1
- for(var i = 0; i < joaninhas.length; i++){//for all members of population
- if(number > probability && number < joaninhas[i+1].score){//if number > probability but less than next probability
- pais[x] = joaninhas[i];//then you have been selected
- }
- }//end for
- x++;
- }//end
- //create offspring
- break;
- }//end loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement