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
EvolutionStream
s
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 newEvolutionStreamable
instance where all createdEvolutionStream
s are limited to the given number of generations.default EvolutionStreamable
<G, C> 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.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> 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 emptyPopulation
is 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 evolutionstart
isnull
.
-
stream
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 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 evolutionstart
isnull
.
-
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 emptyPopulation
is 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 evolutionstart
isnull
.
-
stream
Create a newEvolutionStream
starting with a previously evolvedEvolutionResult
. The stream is initialized with the population of the givenresult
and its total generationEvolutionResult.totalGenerations()
.private 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
Create a new, possibly infinite, evolution stream with the given initial population. If an emptyPopulation
is 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 givenpopulation
isnull
.IllegalArgumentException
- if the givengeneration
is smaller then one
-
stream
Create a new, possibly infinite, evolution stream with the given initial population. If an emptyPopulation
is 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 givenpopulation
isnull
.
-
stream
Create a new, possibly infinite, evolution stream with the given initial individuals. If an emptyIterable
is 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 givengenotypes
isnull
.IllegalArgumentException
- if the givengeneration
is smaller then one
-
stream
Create a new, possibly infinite, evolution stream with the given initial individuals. If an emptyIterable
is 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 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 have 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
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.
-