C   40

rep

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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include "type.h"
  5.  
  6.  
  7. void rawStat();
  8.  
  9. void report(int gen, POPULATION *p, IPTR  pop)
  10. { /* report generations stats */
  11.   FILE *fp;
  12.   int err;
  13.   if( (fp = fopen(p->ofile, "a")) == NULL){
  14.     err = printf("error in opening file %s \n", p->ofile);
  15.     exit(1);
  16.   }else{
  17.     rawStat(fp, p, pop);
  18.     fclose(fp);
  19.   }
  20.   rawStat(stdout, p, pop);
  21.  
  22.  
  23. }
  24.  
  25. void rawStat(FILE *fp, POPULATION *p, IPTR pop)
  26. {
  27.   int err;
  28.   err = fprintf(fp," %3d %10.2lf %10.2lf %10.2lf ", p->gen, p->max,
  29.           p->avg, p->min);
  30.   err = fprintf(fp," %3d %10.2lf %3d", p->highestEverGen,  p->highestEverFitness,
  31.           p->highestEverIndex);
  32.   err = fprintf(fp," %10.2lf\n", pop[p->maxi].fitness);
  33. }

Raw Paste


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