C   35

stats

Guest on 29th June 2022 08:06:10 AM

  1. #include <stdio.h>
  2. /*#include <math.h>*/
  3.  
  4.  
  5. #include "type.h"
  6.  
  7. void statistics(POPULATION *p, IPTR pop)
  8. { /* calculate population stats */
  9.   int size, i, j, s;
  10.   IPTR pi;
  11.  
  12.   p->sumFitness = pop[0].fitness;
  13.   p->max = p->sumFitness;
  14.   p->min = p->sumFitness;
  15.   p->maxi = p->mini = 0;
  16.   for(i = 1; i < p->popSize; i++){
  17.     pi = &(pop[i]);
  18.     p->sumFitness += pi->fitness;
  19.     if (p->max < pi->fitness) {
  20.       p->max = pi->fitness;   p->maxi = i;
  21.     }
  22.     if (p->min > pi->fitness){
  23.       p->min = pi->fitness;   p->mini = i;
  24.     }
  25.   }
  26.   p->avg = p->sumFitness / (double) p->popSize;
  27.   if(p->highestEverFitness < p->max) {
  28.     p->highestEverFitness = p->max;
  29.     p->highestEverGen = p->gen;
  30.     p->highestEverIndex = p->maxi;
  31.   }
  32. }

Raw Paste


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