Package io.jenetics.engine
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 typeC
- 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:
EvolutionStart
,Engine
, Serialized Form- Implementation Note:
- This class is immutable and thread-safe.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
alterCount()
The number of altered individuals.C
bestFitness()
Return the best population fitness.Phenotype<G,C>
bestPhenotype()
Return the bestPhenotype
of the result population.int
compareTo(EvolutionResult<G,C> other)
Comparethis
evolution result with another one, according the populations best individual.EvolutionDurations
durations()
Return the timing (meta) information of the evolution step.boolean
equals(Object obj)
long
generation()
The current generation.ISeq<Genotype<G>>
genotypes()
Return the current list of genotypes of this evolution result.int
hashCode()
int
invalidCount()
Return the number of invalid individuals.int
killCount()
Return the number of killed individuals.EvolutionStart<G,C>
next()
Return the next evolution start object with the current population and the incremented generation.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 an newEvolutionResult
object with the given values.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 an newEvolutionResult
object with the given values.Optimize
optimize()
Return the optimization strategy used.ISeq<Phenotype<G,C>>
population()
Return the population after the evolution step.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.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.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.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).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).EvolutionStart<G,C>
toEvolutionStart()
Return the current evolution result object as anEvolutionStart
object with the current population and current total generation.long
totalGenerations()
Return the generation count evaluated so far.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.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.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 genotypefactory
.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 genotypefactory
.C
worstFitness()
Return the worst population fitness.Phenotype<G,C>
worstPhenotype()
Return the worstPhenotype
of the result population.
-
-
-
Method Detail
-
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
public EvolutionDurations 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
public Phenotype<G,C> bestPhenotype()
Return the bestPhenotype
of the result population.- Returns:
- the best
Phenotype
of the result population
-
worstPhenotype
public Phenotype<G,C> worstPhenotype()
Return the worstPhenotype
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
public EvolutionStart<G,C> toEvolutionStart()
Return the current evolution result object as anEvolutionStart
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)
Comparethis
evolution result with another one, according the populations best individual.- Specified by:
compareTo
in interfaceComparable<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.
-
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.If the collectedfinal 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());
EvolutionStream
is empty, the collector returnsnull
.- Type Parameters:
G
- the gene typeC
- 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.If the collectedfinal 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());
EvolutionStream
is empty, the collector returnsnull
.- Type Parameters:
G
- the gene typeC
- 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.If the collectedfinal 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());
EvolutionStream
is empty, the collector returnsnull
.- Type Parameters:
G
- the gene typeC
- 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).If the collectedfinal 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()));
EvolutionStream
is empty, the collector returnsnull
.- Type Parameters:
T
- the native problem result typeG
- the gene typeC
- the fitness result type- Parameters:
decoder
- the decoder which converts theGenotype
into the result of the problem space.- Returns:
- a collector which collects the best result of an evolution stream
- Throws:
NullPointerException
- if the givendecoder
isnull
- 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).If the collectedfinal 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()));
EvolutionStream
is empty, the collector returnsnull
.- Type Parameters:
T
- the native problem result typeG
- the gene typeC
- 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 givencodec
isnull
- 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 genotypefactory
.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 typeC
- the fitness function result type- Parameters:
factory
- the genotype factory which create new individualsmaxRetries
- the maximal number of genotype creation tries- Returns:
- a mapping function, which removes duplicate individuals from the population
- Throws:
NullPointerException
- if the given genotypefactory
isnull
- Since:
- 6.0
- See Also:
Engine.Builder.interceptor(EvolutionInterceptor)
-
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 genotypefactory
.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 typeC
- the fitness function result type- Parameters:
factory
- the genotype factory which create new individuals- Returns:
- a mapping function, which removes duplicate individuals from the population
- Throws:
NullPointerException
- if the given genotypefactory
isnull
- Since:
- 6.0
- See Also:
Engine.Builder.interceptor(EvolutionInterceptor)
-
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 typeC
- the fitness function result type- Parameters:
maxRetries
- the maximal number of genotype creation tries- Returns:
- a mapping function, which removes duplicate individuals from the population
- Throws:
NullPointerException
- if the given genotypefactory
isnull
- Since:
- 6.0
- See Also:
Engine.Builder.interceptor(EvolutionInterceptor)
-
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 typeC
- the fitness function result type- Returns:
- a mapping function, which removes duplicate individuals from the population
- Throws:
NullPointerException
- if the given genotypefactory
isnull
- Since:
- 6.0
- See Also:
Engine.Builder.interceptor(EvolutionInterceptor)
-
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 an newEvolutionResult
object with the given values.- Type Parameters:
G
- the gene typeC
- the fitness type- Parameters:
optimize
- the optimization strategy usedpopulation
- the population after the evolution stepgeneration
- the current generationtotalGenerations
- the overall number of generationsdurations
- the timing (meta) informationkillCount
- the number of individuals which has been killedinvalidCount
- the number of individuals which has been removed as invalidalterCount
- the number of individuals which has been altered- Returns:
- an new evolution result object
- Throws:
NullPointerException
- if one of the parameters isnull
-
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 an newEvolutionResult
object with the given values.- Type Parameters:
G
- the gene typeC
- the fitness type- Parameters:
optimize
- the optimization strategy usedpopulation
- the population after the evolution stepgeneration
- the current generationdurations
- the timing (meta) informationkillCount
- the number of individuals which has been killedinvalidCount
- the number of individuals which has been removed as invalidalterCount
- the number of individuals which has been altered- Returns:
- an new evolution result object
- Throws:
NullPointerException
- if one of the parameters isnull
-
-