public interface EvolutionStreamable<G extends Gene<?,G>,C extends Comparable<? super C>>
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.EvolutionStream| Modifier and Type | Method and Description |
|---|---|
default EvolutionStreamable<G,C> |
limit(long generations)
Return a new
EvolutionStreamable instance where all created
EvolutionStreams are limited to the given number of generations. |
default EvolutionStreamable<G,C> |
limit(Supplier<Predicate<? super EvolutionResult<G,C>>> proceed)
Return a new
EvolutionStreamable instance where all created
EvolutionStreams 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 new
EvolutionStream starting with a previously evolved
EvolutionResult. |
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.
|
EvolutionStream<G,C> stream(Supplier<EvolutionStart<G,C>> start)
Population 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.start - the data the evolution stream starts withNullPointerException - if the given evolution
start is null.EvolutionStream<G,C> stream(EvolutionInit<G> init)
Population 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.init - the data the evolution stream is initialized withNullPointerException - if the given evolution
start is null.default EvolutionStream<G,C> stream()
final EvolutionStream<G, C> stream = streamable
.stream(() -> EvolutionStart.of(ISeq.empty(), 1));default EvolutionStream<G,C> stream(EvolutionStart<G,C> start)
Population 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.start - the data the evolution stream starts withNullPointerException - if the given evolution
start is null.default EvolutionStream<G,C> stream(EvolutionResult<G,C> result)
EvolutionStream starting with a previously evolved
EvolutionResult. The stream is initialized with the population
of the given result and its total generation
EvolutionResult.getTotalGenerations().
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.getBestPhenotype());
}EvolutionResult from a
first run, save it to disk and continue the evolution.result - the previously evolved EvolutionResultNullPointerException - if the given evolution result is
nulldefault EvolutionStream<G,C> stream(ISeq<Phenotype<G,C>> population, long generation)
Population 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.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.NullPointerException - if the given population is
null.IllegalArgumentException - if the given generation is
smaller then onedefault EvolutionStream<G,C> stream(ISeq<Phenotype<G,C>> population)
Population 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.population - the initial individuals used for the evolution stream.
Missing individuals are created and individuals not needed are
skipped.NullPointerException - if the given population is
null.default EvolutionStream<G,C> stream(Iterable<Genotype<G>> genotypes, long generation)
Iterable is given, the engines
genotype factory is used for creating the population.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.NullPointerException - if the given genotypes is
null.IllegalArgumentException - if the given generation is
smaller then onedefault EvolutionStream<G,C> stream(Iterable<Genotype<G>> genotypes)
Iterable is given, the engines
genotype factory is used for creating the population.genotypes - the initial individuals used for the evolution stream.
Missing individuals are created and individuals not needed are
skipped.NullPointerException - if the given genotypes is
null.default EvolutionStreamable<G,C> limit(Supplier<Predicate<? super EvolutionResult<G,C>>> proceed)
EvolutionStreamable instance where all created
EvolutionStreams are limited by the given predicate. Since some
predicates has to maintain internal state, a predicate Supplier
must be given instead a plain limiting predicate.proceed - the limiting predicate supplier.NullPointerException - if the give predicate is nulldefault EvolutionStreamable<G,C> limit(long generations)
EvolutionStreamable instance where all created
EvolutionStreams are limited to the given number of generations.generations - the number of generations after the created evolution
streams are truncatedIllegalArgumentException - if the given generations is
smaller than zero.© 2007-2019 Franz Wilhelmstötter (2019-02-19 21:44)