Termination Problem: redundant ObjFunc evaluation
Matthew Wall
mbwall at MIT.EDU
Fri Jun 2 09:22:20 EDT 2000
if you use the 'score' method instead of the invoking your objective
function directly then you will not have to re-evaluate.
GAGenome::score caches the score returned by the objective function
(and well-behaved genomes mark the cache as dirty when they change
state).
so instead of
double y = objective(genome);
do this:
double y = ga.statistics().bestIndividual().score();
>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