Module io.jenetics.base
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:
- Implementation Note:
- This class is immutable and thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionint
The number of altered individuals.Return the best population fitness.Return the bestPhenotype
of the result population.int
compareTo
(EvolutionResult<G, C> other) Comparethis
evolution result with another one, according the population's best individual.Return the timing (meta) information of the evolution step.boolean
long
The current generation.Return the current list of genotypes of this evolution result.int
hashCode()
int
Return the number of invalid individuals.int
Return the number of killed individuals.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 a 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 a newEvolutionResult
object with the given values.optimize()
Return the optimization strategy used.Return the population after the evolution step.static <G extends Gene<?,
G>, C extends Comparable<? super C>>
Collector<EvolutionResult<G,C>, ?, EvolutionResult<G, C>> 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>> 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>> 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).Return the current evolution result object as anEvolutionStart
object with the current population and current total generation.long
Return the generation count evaluated so far.static <G extends Gene<?,
G>, C extends Comparable<? super C>>
EvolutionInterceptor<G,C> 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
.Return the worst population fitness.Return the worstPhenotype
of the result population.
-
Method Details
-
optimize
Return the optimization strategy used.- Returns:
- the optimization strategy used
-
population
Return the population after the evolution step.- Returns:
- the population after the evolution step
-
genotypes
Return the current list of genotypes of this evolution result.- Returns:
- the list of genotypes of this evolution result.
- Since:
- 5.2
-
generation
The current generation.- Returns:
- the current generation
-
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
Return the number of killed individuals.- Returns:
- the number of killed individuals
-
invalidCount
Return the number of invalid individuals.- Returns:
- the number of invalid individuals
-
alterCount
The number of altered individuals.- Returns:
- the number of altered individuals
-
bestPhenotype
Return the bestPhenotype
of the result population.- Returns:
- the best
Phenotype
of the result population
-
worstPhenotype
Return the worstPhenotype
of the result population.- Returns:
- the worst
Phenotype
of the result population
-
bestFitness
Return the best population fitness.- Returns:
- The best population fitness.
-
worstFitness
Return the worst population fitness.- Returns:
- The worst population fitness.
-
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 anEvolutionStart
object with the current population and current total generation.- Returns:
- the current result as evolution start
- Since:
- 4.1
-
compareTo
Comparethis
evolution result with another one, according the population's 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.
-
hashCode
-
equals
-
toBestEvolutionResult
public static <G extends Gene<?,G>, Collector<EvolutionResult<G,C extends Comparable<? super C>> C>, toBestEvolutionResult()?, EvolutionResult<G, C>> 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>, Collector<EvolutionResult<G,C extends Comparable<? super C>> C>, toBestPhenotype()?, Phenotype<G, C>> 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>, Collector<EvolutionResult<G,C extends Comparable<? super C>> C>, toBestGenotype()?, Genotype<G>> 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>, Collector<EvolutionResult<G,C extends Comparable<? super C>, T> C>, toBestResult?, T> (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>, Collector<EvolutionResult<G,C extends Comparable<? super C>, T> C>, toBestResult?, T> (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>, EvolutionInterceptor<G,C extends Comparable<? super C>> 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 creates new individualsmaxRetries
- the maximal number of genotype creations tries- Returns:
- a mapping function, which removes duplicate individuals from the population
- Throws:
NullPointerException
- if the given genotypefactory
isnull
- Since:
- 6.0
- See Also:
-
toUniquePopulation
public static <G extends Gene<?,G>, EvolutionInterceptor<G,C extends Comparable<? super C>> 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 creates 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:
-
toUniquePopulation
public static <G extends Gene<?,G>, EvolutionInterceptor<G,C extends Comparable<? super C>> 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 creations tries- Returns:
- a mapping function, which removes duplicate individuals from the population
- Throws:
NullPointerException
- if the given genotypefactory
isnull
- Since:
- 6.0
- See Also:
-
toUniquePopulation
public static <G extends Gene<?,G>, EvolutionInterceptor<G,C extends Comparable<? super C>> 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:
-
of
public static <G extends Gene<?,G>, EvolutionResult<G,C extends Comparable<? super C>> C> of(Optimize optimize, ISeq<Phenotype<G, C>> population, long generation, long totalGenerations, EvolutionDurations durations, int killCount, int invalidCount, int alterCount) Return a 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>, EvolutionResult<G,C extends Comparable<? super C>> C> of(Optimize optimize, ISeq<Phenotype<G, C>> population, long generation, EvolutionDurations durations, int killCount, int invalidCount, int alterCount) Return a 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
-