Package io.jenetics.engine
Interface EvolutionStreamable<G extends Gene<?,G>,C extends Comparable<? super C>>
-
- All Known Implementing Classes:
Engine
public interface EvolutionStreamable<G extends Gene<?,G>,C extends Comparable<? super C>>
This interface defines the capability of creatingEvolutionStream
s from a givenEvolutionStart
object. It also decouples the engine's capability from the capability to create evolution streams. The purpose of this interface is similar to theIterable
interface.- Since:
- 4.1
- Version:
- 4.1
- Author:
- Franz Wilhelmstötter
- See Also:
EvolutionStream
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default EvolutionStreamable<G,C>
limit(long generations)
Return a newEvolutionStreamable
instance where all createdEvolutionStream
s are limited to the given number of generations.default EvolutionStreamable<G,C>
limit(Supplier<? extends Predicate<? super EvolutionResult<G,C>>> proceed)
Return a newEvolutionStreamable
instance where all createdEvolutionStream
s are limited by the given predicate.default EvolutionStream<G,C>
stream()
Create a new, possibly infinite, evolution stream with a newly created population.EvolutionStream<G,C>
stream(EvolutionInit<G> init)
Create a new, possibly infinite, evolution stream with the given initial value.default EvolutionStream<G,C>
stream(EvolutionResult<G,C> result)
Create a newEvolutionStream
starting with a previously evolvedEvolutionResult
.default EvolutionStream<G,C>
stream(EvolutionStart<G,C> start)
Create a new, possibly infinite, evolution stream with the given evolution start.default EvolutionStream<G,C>
stream(ISeq<Phenotype<G,C>> population)
Create a new, possibly infinite, evolution stream with the given initial population.default EvolutionStream<G,C>
stream(ISeq<Phenotype<G,C>> population, long generation)
Create a new, possibly infinite, evolution stream with the given initial population.default EvolutionStream<G,C>
stream(Iterable<Genotype<G>> genotypes)
Create a new, possibly infinite, evolution stream with the given initial individuals.default EvolutionStream<G,C>
stream(Iterable<Genotype<G>> genotypes, long generation)
Create a new, possibly infinite, evolution stream with the given initial individuals.EvolutionStream<G,C>
stream(Supplier<EvolutionStart<G,C>> start)
Create a new, possibly infinite, evolution stream with the given evolution start.
-
-
-
Method Detail
-
stream
EvolutionStream<G,C> stream(Supplier<EvolutionStart<G,C>> start)
Create a new, possibly infinite, evolution stream with the given evolution start. If an emptyPopulation
is given, the engines genotype factory is used for creating the population. The given population might be the result of an other engine and this method allows to start the evolution with the outcome of an different engine. The fitness function and the fitness scaler are replaced by the one defined for this engine.- Parameters:
start
- the data the evolution stream starts with- Returns:
- a new infinite evolution stream
- Throws:
NullPointerException
- if the given evolutionstart
isnull
.
-
stream
EvolutionStream<G,C> stream(EvolutionInit<G> init)
Create a new, possibly infinite, evolution stream with the given initial value. If an emptyPopulation
is given, the engines genotype factory is used for creating the population. The given population might be the result of an other engine and this method allows to start the evolution with the outcome of an different engine. The fitness function and the fitness scaler are replaced by the one defined for this engine.- Parameters:
init
- the data the evolution stream is initialized with- Returns:
- a new infinite evolution stream
- Throws:
NullPointerException
- if the given evolutionstart
isnull
.
-
stream
default EvolutionStream<G,C> stream()
Create a new, possibly infinite, evolution stream with a newly created population. This method is a shortcut forfinal EvolutionStream<G, C> stream = streamable .stream(() -> EvolutionStart.of(ISeq.empty(), 1));
- Returns:
- a new evolution stream.
-
stream
default EvolutionStream<G,C> stream(EvolutionStart<G,C> start)
Create a new, possibly infinite, evolution stream with the given evolution start. If an emptyPopulation
is given, the engines genotype factory is used for creating the population. The given population might be the result of an other engine and this method allows to start the evolution with the outcome of an different engine. The fitness function and the fitness scaler are replaced by the one defined for this engine.- Parameters:
start
- the data the evolution stream starts with- Returns:
- a new infinite evolution iterator
- Throws:
NullPointerException
- if the given evolutionstart
isnull
.
-
stream
default EvolutionStream<G,C> stream(EvolutionResult<G,C> result)
Create a newEvolutionStream
starting with a previously evolvedEvolutionResult
. The stream is initialized with the population of the givenresult
and its total generationEvolutionResult.totalGenerations()
.The example above shows how to save anprivate static final Problem<Double, DoubleGene, Double> PROBLEM = Problem.of( x -> cos(0.5 + sin(x))*cos(x), Codecs.ofScalar(DoubleRange.of(0.0, 2.0*PI)) ); private static final Engine<DoubleGene, Double> ENGINE = Engine.builder(PROBLEM) .optimize(Optimize.MINIMUM) .offspringSelector(new RouletteWheelSelector<>()) .build(); public static void main(final String[] args) throws IOException { // Result of the first evolution run. final EvolutionResult<DoubleGene, Double> rescue = ENGINE.stream() .limit(Limits.bySteadyFitness(10)) .collect(EvolutionResult.toBestEvolutionResult()); // Save the result of the first run into a file. final Path path = Paths.get("result.bin"); IO.object.write(rescue, path); // Load the previous result and continue evolution. @SuppressWarnings("unchecked") final EvolutionResult<DoubleGene, Double> result = ENGINE .stream((EvolutionResult<DoubleGene, Double>)IO.object.read(path)) .limit(Limits.bySteadyFitness(20)) .collect(EvolutionResult.toBestEvolutionResult()); System.out.println(result.bestPhenotype()); }
EvolutionResult
from a first run, save it to disk and continue the evolution.- Parameters:
result
- the previously evolvedEvolutionResult
- Returns:
- a new evolution stream, which continues a previous one
- Throws:
NullPointerException
- if the given evolutionresult
isnull
-
stream
default EvolutionStream<G,C> stream(ISeq<Phenotype<G,C>> population, long generation)
Create a new, possibly infinite, evolution stream with the given initial population. If an emptyPopulation
is given, the engines genotype factory is used for creating the population. The given population might be the result of an other engine and this method allows to start the evolution with the outcome of an different engine. The fitness function and the fitness scaler are replaced by the one defined for this engine.- Parameters:
population
- the initial individuals used for the evolution stream. Missing individuals are created and individuals not needed are skipped.generation
- the generation the stream starts from; must be greater than zero.- Returns:
- a new evolution stream.
- Throws:
NullPointerException
- if the givenpopulation
isnull
.IllegalArgumentException
- if the givengeneration
is smaller then one
-
stream
default EvolutionStream<G,C> stream(ISeq<Phenotype<G,C>> population)
Create a new, possibly infinite, evolution stream with the given initial population. If an emptyPopulation
is given, the engines genotype factory is used for creating the population. The given population might be the result of an other engine and this method allows to start the evolution with the outcome of an different engine. The fitness function and the fitness scaler are replaced by the one defined for this engine.- Parameters:
population
- the initial individuals used for the evolution stream. Missing individuals are created and individuals not needed are skipped.- Returns:
- a new evolution stream.
- Throws:
NullPointerException
- if the givenpopulation
isnull
.
-
stream
default EvolutionStream<G,C> stream(Iterable<Genotype<G>> genotypes, long generation)
Create a new, possibly infinite, evolution stream with the given initial individuals. If an emptyIterable
is given, the engines genotype factory is used for creating the population.- Parameters:
genotypes
- the initial individuals used for the evolution stream. Missing individuals are created and individuals not needed are skipped.generation
- the generation the stream starts from; must be greater than zero.- Returns:
- a new evolution stream.
- Throws:
NullPointerException
- if the givengenotypes
isnull
.IllegalArgumentException
- if the givengeneration
is smaller then one
-
stream
default EvolutionStream<G,C> stream(Iterable<Genotype<G>> genotypes)
Create a new, possibly infinite, evolution stream with the given initial individuals. If an emptyIterable
is given, the engines genotype factory is used for creating the population.- Parameters:
genotypes
- the initial individuals used for the evolution stream. Missing individuals are created and individuals not needed are skipped.- Returns:
- a new evolution stream.
- Throws:
NullPointerException
- if the givengenotypes
isnull
.
-
limit
default EvolutionStreamable<G,C> limit(Supplier<? extends Predicate<? super EvolutionResult<G,C>>> proceed)
Return a newEvolutionStreamable
instance where all createdEvolutionStream
s are limited by the given predicate. Since some predicates has to maintain internal state, a predicateSupplier
must be given instead a plain limiting predicate.- Parameters:
proceed
- the limiting predicate supplier.- Returns:
- a new evolution streamable object
- Throws:
NullPointerException
- if the givepredicate
isnull
-
limit
default EvolutionStreamable<G,C> limit(long generations)
Return a newEvolutionStreamable
instance where all createdEvolutionStream
s are limited to the given number of generations.- Parameters:
generations
- the number of generations after the created evolution streams are truncated- Returns:
- a new evolution streamable object
- Throws:
IllegalArgumentException
- if the givengenerations
is smaller than zero.
-
-