Termination Problem: redundant ObjFunc evaluation

Martin MacRobert martin at mediavillage.org.au
Tue May 16 05:30:39 EDT 2000


Hi All,
I'm trying to find a better way to perform the terminate function.
At the moment I need to terminate on a generation limit, but also when a
solution falls within a user specified tolerance. The performance
bottleneck happens here. You'll notice in the code snippet that I
re-evaluate the genome in order to get an objective value, which I
should already have. Is there a direct way to get the objective value,
without re-evaluating as shown below?
Many thanks,
Martin

#define TOLERANCE 0.00001

GABoolean terminate(GAGeneticAlgorithm & ga)
{

 GABin2DecGenome& genome
= (GABin2DecGenome &)ga.statistics().bestIndividual();
 double y = objective(genome);

 GABoolean bWithinTolerance = ((fabs(y) <= TOLERANCE ) ? gaTrue :
gaFalse );
 GABoolean bGeneration = ((ga.generation() < ga.nGenerations()) ?
gaFalse : gaTrue);

 if ((bWithinTolerance == gaTrue)||
  (bGeneration == gaTrue))
 {
  if (bWithinTolerance == gaTrue)
  {
   cout << "Tolerance achieved: " << TOLERANCE << "\n";
  }
  cout << "Terminating on generation: " << ga.generation() << '\n';
  return gaTrue;
 }

 return gaFalse;
}








More information about the galib mailing list