Module io.jenetics.base
Package io.jenetics.engine
Interface EvolutionStreamable<G extends Gene<?,G>,C extends Comparable<? super C>>
- All Known Implementing Classes:
ConcatEngine,CyclicEngine,Engine
public interface EvolutionStreamable<G extends Gene<?,G>,C extends Comparable<? super C>>
This interface defines the capability of creating
EvolutionStreams
from a given EvolutionStart object. It also decouples the engine's
capability from the capability to create evolution streams. The purpose of
this interface is similar to the Iterable interface.- Since:
- 4.1
- Version:
- 4.1
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault EvolutionStreamable<G, C> limit(long generations) Return a newEvolutionStreamableinstance where all createdEvolutionStreams are limited to the given number of generations.default EvolutionStreamable<G, C> Return a newEvolutionStreamableinstance where all createdEvolutionStreams are limited by the given predicate.default EvolutionStream<G, C> stream()Create a new, possibly infinite, evolution stream with a newly created population.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 newEvolutionStreamstarting 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> Create a new, possibly infinite, evolution stream with the given initial population.default EvolutionStream<G, C> Create a new, possibly infinite, evolution stream with the given initial population.default EvolutionStream<G, C> Create a new, possibly infinite, evolution stream with the given initial individuals.default EvolutionStream<G, C> Create a new, possibly infinite, evolution stream with the given initial individuals.stream(Supplier<EvolutionStart<G, C>> start) Create a new, possibly infinite, evolution stream with the given evolution start.
-
Method Details
-
stream
Create a new, possibly infinite, evolution stream with the given evolution start. If an emptyPopulationis given, the engine's genotype factory is used for creating the population. The given population might be the result of another engine, and this method allows to start the evolution with the outcome of a different engine. The fitness function is 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 evolutionstartisnull.
-
stream
Create a new, possibly infinite, evolution stream with the given initial value. If an emptyPopulationis given, the engines genotype factory is used for creating the population. The given population might be the result of another engine, and this method allows to start the evolution with the outcome of a different engine. The fitness function is 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 evolutionstartisnull.
-
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
Create a new, possibly infinite, evolution stream with the given evolution start. If an emptyPopulationis given, the engine's genotype factory is used for creating the population. The given population might be the result of another engine, and this method allows to start the evolution with the outcome of a different engine. The fitness function is 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 evolutionstartisnull.
-
stream
Create a newEvolutionStreamstarting with a previously evolvedEvolutionResult. The stream is initialized with the population of the givenresultand 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()); }EvolutionResultfrom 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 evolutionresultisnull
-
stream
Create a new, possibly infinite, evolution stream with the given initial population. If an emptyPopulationis given, the engine's genotype factory is used for creating the population. The given population might be the result of another engine, and this method allows to start the evolution with the outcome of a different engine. The fitness function is 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 givenpopulationisnull.IllegalArgumentException- if the givengenerationis smaller then one
-
stream
Create a new, possibly infinite, evolution stream with the given initial population. If an emptyPopulationis given, the engine's genotype factory is used for creating the population. The given population might be the result of another engine, and this method allows to start the evolution with the outcome of a different engine. The fitness function is 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 givenpopulationisnull.
-
stream
Create a new, possibly infinite, evolution stream with the given initial individuals. If an emptyIterableis given, the engine's 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 givengenotypesisnull.IllegalArgumentException- if the givengenerationis smaller then one
-
stream
Create a new, possibly infinite, evolution stream with the given initial individuals. If an emptyIterableis given, the engine's 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 givengenotypesisnull.
-
limit
default EvolutionStreamable<G,C> limit(Supplier<? extends Predicate<? super EvolutionResult<G, C>>> proceed) Return a newEvolutionStreamableinstance where all createdEvolutionStreams are limited by the given predicate. Since some predicates have to maintain internal state, a predicateSuppliermust be given instead a plain limiting predicate.- Parameters:
proceed- the limiting predicate supplier.- Returns:
- a new evolution-streamable object
- Throws:
NullPointerException- if the givepredicateisnull
-
limit
Return a newEvolutionStreamableinstance where all createdEvolutionStreams 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 givengenerationsis smaller than zero.
-