C   41

select

Guest on 29th June 2022 08:07:03 AM

  1. #include "type.h"
  2.  
  3. double f_random();
  4.  
  5. int roulette(IPTR pop, double sumFitness, int popsize)
  6. {
  7.  
  8.   /* select a single individual by roulette wheel selection */
  9.  
  10.   double rand,partsum;
  11.   int i;
  12.  
  13.   partsum = 0.0; i = 0;
  14.   rand = f_random() * sumFitness;
  15.  
  16.   i = -1;
  17.   do{
  18.     i++;
  19.     partsum += pop[i].fitness;
  20.   } while (partsum < rand && i < popsize - 1) ;
  21.  
  22.   return i;
  23. }

Raw Paste


Login or Register to edit or fork this paste. It's free.