Class EvolutionResult<G extends Gene<?,G>,C extends Comparable<? super C>>

java.lang.Object
io.jenetics.engine.EvolutionResult<G,C>
Type Parameters:
G - the gene type
C - the fitness type
All Implemented Interfaces:
Serializable, Comparable<EvolutionResult<G,C>>

public final class EvolutionResult<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Comparable<EvolutionResult<G,C>>, Serializable
Represents a state of the GA after an evolution step. It also represents the final state of an evolution process and can be created with an appropriate collector:
final Problem<ISeq<Point>, EnumGene<Point>, Double> tsm = ...; final EvolutionResult<EnumGene<Point>, Double> result = Engine.builder(tsm) .optimize(Optimize.MINIMUM).build() .stream() .limit(100) .collect(EvolutionResult.toBestEvolutionResult());
Since:
3.0
Version:
6.0
See Also:
Implementation Note:
This class is immutable and thread-safe.
  • Method Details

    • optimize

      public Optimize optimize()
      Return the optimization strategy used.
      Returns:
      the optimization strategy used
    • population

      public ISeq<Phenotype<G,C>> population()
      Return the population after the evolution step.
      Returns:
      the population after the evolution step
    • genotypes

      public ISeq<Genotype<G>> genotypes()
      Return the current list of genotypes of this evolution result.
      Returns:
      the list of genotypes of this evolution result.
      Since:
      5.2
    • generation

      public long generation()
      The current generation.
      Returns:
      the current generation
    • totalGenerations

      public long totalGenerations()
      Return the generation count evaluated so far.
      Returns:
      the total number of generations evaluated so far
    • durations

      Return the timing (meta) information of the evolution step.
      Returns:
      the timing (meta) information of the evolution step
    • killCount

      public int killCount()
      Return the number of killed individuals.
      Returns:
      the number of killed individuals
    • invalidCount

      public int invalidCount()
      Return the number of invalid individuals.
      Returns:
      the number of invalid individuals
    • alterCount

      public int alterCount()
      The number of altered individuals.
      Returns:
      the number of altered individuals
    • bestPhenotype

      Return the best Phenotype of the result population.
      Returns:
      the best Phenotype of the result population
    • worstPhenotype

      Return the worst Phenotype of the result population.
      Returns:
      the worst Phenotype of the result population
    • bestFitness

      public C bestFitness()
      Return the best population fitness.
      Returns:
      The best population fitness.
    • worstFitness

      public C worstFitness()
      Return the worst population fitness.
      Returns:
      The worst population fitness.
    • next

      public EvolutionStart<G,C> next()
      Return the next evolution start object with the current population and the incremented generation.
      Returns:
      the next evolution start object
      Since:
      4.1
    • toEvolutionStart

      Return the current evolution result object as an EvolutionStart object with the current population and current total generation.
      Returns:
      the current result as evolution start
      Since:
      4.1
    • compareTo

      public int compareTo(EvolutionResult<G,C> other)
      Compare this evolution result with another one, according the population's best individual.
      Specified by:
      compareTo in interface Comparable<G extends Gene<?,G>>
      Parameters:
      other - the other evolution result to compare
      Returns:
      a negative integer, zero, or a positive integer as this result is less than, equal to, or greater than the specified result.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toBestEvolutionResult

      public static <G extends Gene<?, G>, C extends Comparable<? super C>> Collector<EvolutionResult<G,C>,?,EvolutionResult<G,C>> toBestEvolutionResult()
      Return a collector which collects the best result of an evolution stream.
      final Problem<ISeq<Point>, EnumGene<Point>, Double> tsm = ...; final EvolutionResult<EnumGene<Point>, Double> result = Engine.builder(tsm) .optimize(Optimize.MINIMUM).build() .stream() .limit(100) .collect(EvolutionResult.toBestEvolutionResult());
      If the collected EvolutionStream is empty, the collector returns null.
      Type Parameters:
      G - the gene type
      C - the fitness type
      Returns:
      a collector which collects the best result of an evolution stream
    • toBestPhenotype

      public static <G extends Gene<?, G>, C extends Comparable<? super C>> Collector<EvolutionResult<G,C>,?,Phenotype<G,C>> toBestPhenotype()
      Return a collector which collects the best phenotype of an evolution stream.
      final Problem<ISeq<Point>, EnumGene<Point>, Double> tsm = ...; final Phenotype<EnumGene<Point>, Double> result = Engine.builder(tsm) .optimize(Optimize.MINIMUM).build() .stream() .limit(100) .collect(EvolutionResult.toBestPhenotype());
      If the collected EvolutionStream is empty, the collector returns null.
      Type Parameters:
      G - the gene type
      C - the fitness type
      Returns:
      a collector which collects the best phenotype of an evolution stream
    • toBestGenotype

      public static <G extends Gene<?, G>, C extends Comparable<? super C>> Collector<EvolutionResult<G,C>,?,Genotype<G>> toBestGenotype()
      Return a collector which collects the best genotype of an evolution stream.
      final Problem<ISeq<Point>, EnumGene<Point>, Double> tsm = ...; final Genotype<EnumGene<Point>> result = Engine.builder(tsm) .optimize(Optimize.MINIMUM).build() .stream() .limit(100) .collect(EvolutionResult.toBestGenotype());
      If the collected EvolutionStream is empty, the collector returns null.
      Type Parameters:
      G - the gene type
      C - the fitness type
      Returns:
      a collector which collects the best genotype of an evolution stream
    • toBestResult

      public static <G extends Gene<?, G>, C extends Comparable<? super C>, T> Collector<EvolutionResult<G,C>,?,T> toBestResult(Function<Genotype<G>,T> decoder)
      Return a collector which collects the best result (in the native problem space).
      final Problem<ISeq<Point>, EnumGene<Point>, Double> tsm = ...; final ISeq<Point> route = Engine.builder(tsm) .optimize(Optimize.MINIMUM).build() .stream() .limit(100) .collect(EvolutionResult.toBestResult(tsm.codec().decoder()));
      If the collected EvolutionStream is empty, the collector returns null.
      Type Parameters:
      T - the native problem result type
      G - the gene type
      C - the fitness result type
      Parameters:
      decoder - the decoder which converts the Genotype into the result of the problem space.
      Returns:
      a collector which collects the best result of an evolution stream
      Throws:
      NullPointerException - if the given decoder is null
      Since:
      3.6
    • toBestResult

      public static <G extends Gene<?, G>, C extends Comparable<? super C>, T> Collector<EvolutionResult<G,C>,?,T> toBestResult(Codec<T,G> codec)
      Return a collector which collects the best result (in the native problem space).
      final Problem<ISeq<Point>, EnumGene<Point>, Double> tsm = ...; final ISeq<Point> route = Engine.builder(tsm) .optimize(Optimize.MINIMUM).build() .stream() .limit(100) .collect(EvolutionResult.toBestResult(tsm.codec()));
      If the collected EvolutionStream is empty, the collector returns null.
      Type Parameters:
      T - the native problem result type
      G - the gene type
      C - the fitness result type
      Parameters:
      codec - the problem decoder
      Returns:
      a collector which collects the best result of an evolution stream
      Throws:
      NullPointerException - if the given codec is null
      Since:
      3.6
    • toUniquePopulation

      public static <G extends Gene<?, G>, C extends Comparable<? super C>> EvolutionInterceptor<G,C> toUniquePopulation(Factory<Genotype<G>> factory, int maxRetries)
      Return a mapping function, which removes duplicate individuals from the population and replaces it with newly created one by the given genotype factory.
      final Problem<Double, DoubleGene, Integer> problem = ...; final Engine<DoubleGene, Integer> engine = Engine.builder(problem) .interceptor(toUniquePopulation(problem.codec().encoding(), 100)) .build(); final Genotype<DoubleGene> best = engine.stream() .limit(100); .collect(EvolutionResult.toBestGenotype());
      Type Parameters:
      G - the gene type
      C - the fitness function result type
      Parameters:
      factory - the genotype factory which creates new individuals
      maxRetries - the maximal number of genotype creations tries
      Returns:
      a mapping function, which removes duplicate individuals from the population
      Throws:
      NullPointerException - if the given genotype factory is null
      Since:
      6.0
      See Also:
    • toUniquePopulation

      public static <G extends Gene<?, G>, C extends Comparable<? super C>> EvolutionInterceptor<G,C> toUniquePopulation(Factory<Genotype<G>> factory)
      Return a mapping function, which removes duplicate individuals from the population and replaces it with newly created one by the given genotype factory.
      final Problem<Double, DoubleGene, Integer> problem = ...; final Engine<DoubleGene, Integer> engine = Engine.builder(problem) .interceptor(toUniquePopulation(problem.codec().encoding())) .build(); final Genotype<DoubleGene> best = engine.stream() .limit(100); .collect(EvolutionResult.toBestGenotype());
      Type Parameters:
      G - the gene type
      C - the fitness function result type
      Parameters:
      factory - the genotype factory which creates new individuals
      Returns:
      a mapping function, which removes duplicate individuals from the population
      Throws:
      NullPointerException - if the given genotype factory is null
      Since:
      6.0
      See Also:
    • toUniquePopulation

      public static <G extends Gene<?, G>, C extends Comparable<? super C>> EvolutionInterceptor<G,C> toUniquePopulation(int maxRetries)
      Return a mapping function, which removes duplicate individuals from the population and replaces it with newly created one by the existing genotype factory.
      final Problem<Double, DoubleGene, Integer> problem = ...; final Engine<DoubleGene, Integer> engine = Engine.builder(problem) .interceptor(toUniquePopulation(10)) .build(); final Genotype<DoubleGene> best = engine.stream() .limit(100); .collect(EvolutionResult.toBestGenotype(5));
      Type Parameters:
      G - the gene type
      C - the fitness function result type
      Parameters:
      maxRetries - the maximal number of genotype creations tries
      Returns:
      a mapping function, which removes duplicate individuals from the population
      Throws:
      NullPointerException - if the given genotype factory is null
      Since:
      6.0
      See Also:
    • toUniquePopulation

      public static <G extends Gene<?, G>, C extends Comparable<? super C>> EvolutionInterceptor<G,C> toUniquePopulation()
      Return a mapping function, which removes duplicate individuals from the population and replaces it with newly created one by the existing genotype factory.
      final Problem<Double, DoubleGene, Integer> problem = ...; final Engine<DoubleGene, Integer> engine = Engine.builder(problem) .interceptor(EvolutionResult.toUniquePopulation()) .build(); final Genotype<DoubleGene> best = engine.stream() .limit(100); .collect(EvolutionResult.toBestGenotype());
      Type Parameters:
      G - the gene type
      C - the fitness function result type
      Returns:
      a mapping function, which removes duplicate individuals from the population
      Throws:
      NullPointerException - if the given genotype factory is null
      Since:
      6.0
      See Also:
    • of

      public static <G extends Gene<?, G>, C extends Comparable<? super C>> EvolutionResult<G,C> of(Optimize optimize, ISeq<Phenotype<G,C>> population, long generation, long totalGenerations, EvolutionDurations durations, int killCount, int invalidCount, int alterCount)
      Return a new EvolutionResult object with the given values.
      Type Parameters:
      G - the gene type
      C - the fitness type
      Parameters:
      optimize - the optimization strategy used
      population - the population after the evolution step
      generation - the current generation
      totalGenerations - the overall number of generations
      durations - the timing (meta) information
      killCount - the number of individuals which has been killed
      invalidCount - the number of individuals which has been removed as invalid
      alterCount - the number of individuals which has been altered
      Returns:
      an new evolution result object
      Throws:
      NullPointerException - if one of the parameters is null
    • of

      public static <G extends Gene<?, G>, C extends Comparable<? super C>> EvolutionResult<G,C> of(Optimize optimize, ISeq<Phenotype<G,C>> population, long generation, EvolutionDurations durations, int killCount, int invalidCount, int alterCount)
      Return a new EvolutionResult object with the given values.
      Type Parameters:
      G - the gene type
      C - the fitness type
      Parameters:
      optimize - the optimization strategy used
      population - the population after the evolution step
      generation - the current generation
      durations - the timing (meta) information
      killCount - the number of individuals which has been killed
      invalidCount - the number of individuals which has been removed as invalid
      alterCount - the number of individuals which has been altered
      Returns:
      an new evolution result object
      Throws:
      NullPointerException - if one of the parameters is null