[galib] Still can't get generation count inside Objective function

Everardo Robredo turiyasangitananda at gmail.com
Mon Oct 25 02:01:51 EDT 2010


Hi,

Thank you for that quick answer. I tried what you suggested but I keep
getting the following errors:

/usr/include/ga/GAGenome.h: In function ‘float Objective(GAGenome&)’:
/usr/include/ga/GAGenome.h:264: error: ‘GAGeneticAlgorithm*
GAGenome::ga’ is protected
genetic_fann.cpp:94: error: within this context
genetic_fann.cpp:94: error: ‘g->GAGenome::ga’ cannot be used as a function
make: *** [OBJ.x86_64-unknown-linux-gnu/genetic_fann.o] Error 1

This is the code:
float

float Objective(GAGenome& g)
{
  float value;
  ifstream inStream(filename);
  int size[3];
  for (int i=0;i<3;i++)
  inStream >> size[i];
  double conn[58];
  int siz0, siz1, siz2;
  double patrn[size[1]][size[0]];
  double target[size[2]][size[0]];

  for(int j=0; j<size[0]; j++){
    for(int i=0; i<size[1]; i++){
      inStream >> patrn[i][j];
    }
    for(int k=0; k<size[2]; k++){
      inStream >> target[k][j];
    }
  }

  inStream.close();
  siz0=size[0];
  siz1=size[1];
  siz2=size[2];

  double tar[siz2];
  double pat[siz1];

  GAGeneticAlgorithm* gal = g.ga();

  if (gal){
   gal->generation();
  }

  GABin2DecGenome & genome = (GABin2DecGenome &)g;
  int score=0;
  for (int l=0;l<58;l++){
  conn[l]=genome.phenotype(l);
  }

  for (int i=0;i<size[0];i++){
    for (int j=0;j<size[1];j++){
    pat[j]=patrn[j][i];
    }
    for (int k=0;k<size[2];k++){
    tar[k]=target[k][i];
    }
    score+=fann_eval(conn, siz0, siz1, siz2, pat, tar);
  }
  value=(float)siz0/(float)score;
return value;
}


I tried changing GAGenome.h so that GAGeneticAlgorithm* GAGenome::ga
wouldn't be protected but the second error still appears (plus, I'm
guessing changing the main headers is not an intelligent solution).



-- 
Everardo




More information about the galib mailing list