Interface Evaluator<G extends Gene<?,G>,C extends Comparable<? super C>>

Type Parameters:
G - the gene type
C - the fitness result type
All Known Implementing Classes:
Engine
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Evaluator<G extends Gene<?,G>,C extends Comparable<? super C>>
This interface allows defining different strategies for evaluating the fitness functions of a given population. Normally there is no need for overriding the default evaluation strategy, but it might be necessary if you have performance problems and a batched fitness evaluation would solve the problem.

The implementer is free to do the evaluation in place, or create new Phenotype instance and return the newly created one. A simple serial evaluator can easily implement:

final Function<? super Genotype<G>, ? extends C> fitness = ...; final Evaluator<G, C> evaluator = population -> population .map(pt -> pt.eval(fitness)) .asISeq(); final Engine<G, C> engine = new Engine.Builder<>(evaluator, genotypeFactory) .build();
Since:
4.2
Version:
5.0
See Also:
API Note:
The size of the returned, evaluated, phenotype sequence must be exactly the size of the input phenotype sequence, and all phenotypes must have a fitness value assigned (assert population.forAll(Phenotype::isEvaluated);). It is allowed to return the input sequence, after evaluation, as well as a newly created one.
  • Method Summary

    Modifier and Type
    Method
    Description
    eval(Seq<Phenotype<G,C>> population)
    Evaluates the fitness values of the given population.
  • Method Details

    • eval

      ISeq<Phenotype<G,C>> eval(Seq<Phenotype<G,C>> population)
      Evaluates the fitness values of the given population. The given population might contain already evaluated individuals. It is the responsibility of the implementer to filter out already evaluated individuals, if desired.
      Parameters:
      population - the population to evaluate
      Returns:
      the evaluated population. Implementers are free to return the input population or a newly created one.