Class FitnessNullifier<G extends Gene<?,​G>,​C extends Comparable<? super C>>

  • Type Parameters:
    G - the gene type
    C - the fitness result type
    All Implemented Interfaces:
    EvolutionInterceptor<G,​C>

    public final class FitnessNullifier<G extends Gene<?,​G>,​C extends Comparable<? super C>>
    extends Object
    implements EvolutionInterceptor<G,​C>
    This class allows to force a reevaluation of the fitness function. A reevaluation is necessary, if the fitness function changes. Changing the fitness function is not the usual use case, but is necessary for some problems, like symbolic regression analyses with changing input data (time series).
    final var nullifier = new FitnessNullifier<DoubleGene, Double>(); final Engine<DoubleGene, Double> engine = Engine.builder(problem) .interceptor(nullifier) .build(); // Invalidate fitness value by calling the 'nullifyFitness' method, // possible from a different thread. This forces the reevaluation of // the fitness values at the start of the next generation. nullifier.nullifyFitness();
    Since:
    6.0
    Version:
    6.0
    Author:
    Franz Wilhelmstötter
    See Also:
    Phenotype.nullifyFitness()
    Implementation Note:
    This interceptor is thread-safe and can be used from different threads. No additional synchronization is needed.
    • Method Detail

      • before

        public EvolutionStart<G,​Cbefore​(EvolutionStart<G,​C> start)
        Nullifies the fitness values of the population, if requested. The nullification flag is reset after this call. Two consecutive calls of this method might lead to two different results.
        Specified by:
        before in interface EvolutionInterceptor<G extends Gene<?,​G>,​C extends Comparable<? super C>>
        Parameters:
        start - the evolution start object
        Returns:
        the evolution start object with the nullified fitness values, if the nullification has been triggered
        See Also:
        nullifyFitness()
      • nullifyFitness

        public boolean nullifyFitness()
        Triggers the nullification of the fitness values of the population for the next generation.
        Returns:
        true if the nullification request will trigger a new fitness nullification. @{code false} if the fitness nullification has been requested before, without actually executing it.
        See Also:
        before(EvolutionStart)