Package io.jenetics.ext.engine
Class CyclicEngine<G extends Gene<?,G>,C extends Comparable<? super C>>
- java.lang.Object
-
- io.jenetics.ext.engine.CyclicEngine<G,C>
-
- Type Parameters:
G- the gene typeC- the fitness type
- All Implemented Interfaces:
EvolutionStreamable<G,C>
public final class CyclicEngine<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object
TheCyclicEnginelets you concatenate two (or more) evolutionEngine, with different configurations, and let it use as one engineEvolutionStreamable. If the last evolution stream terminates, it's final result is fed back to first engine.
The+----------+ +----------+ | ES | | ES | +------------+ | +------------+ | (Start) | |-----+ Start | |-----+ ---+---->| Engine 1 |------------>| Engine 2 | --------+ ^ | | Result | | | | +------------+ +------------+ | | | +------------------------------<------------------------+ ResultCyclicEngineallows to do an broad search-fine search-cycle as long as you want.When using afinal Problem<double[], DoubleGene, Double> problem = Problem.of( v -> Math.sin(v[0])*Math.cos(v[1]), Codecs.ofVector(DoubleRange.of(0, 2*Math.PI), 2) ); final Engine<DoubleGene, Double> engine1 = Engine.builder(problem) .minimizing() .alterers(new Mutator<>(0.2)) .selector(new MonteCarloSelector<>()) .build(); final Engine<DoubleGene, Double> engine2 = Engine.builder(problem) .minimizing() .alterers( new Mutator<>(0.1), new MeanAlterer<>()) .selector(new RouletteWheelSelector<>()) .build(); final Genotype<DoubleGene> result = CyclicEngine.of( engine1.limit(50), engine2.limit(() -> Limits.bySteadyFitness(30))) .stream() .limit(Limits.bySteadyFitness(1000)) .collect(EvolutionResult.toBestGenotype()); System.out.println(result + ": " + problem.fitness().apply(problem.codec().decode(result)));CyclicEnginePool, you have to limit the final evolution stream, additionally to the defined limits on the used partial engines.- Since:
- 4.1
- Version:
- 4.1
- See Also:
ConcatEngine
-
-
Constructor Summary
Constructors Constructor Description CyclicEngine(List<? extends EvolutionStreamable<G,C>> engines)Create a new cycling evolution engine with the given list ofengines.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <G extends Gene<?,G>,C extends Comparable<? super C>>
CyclicEngine<G,C>of(EvolutionStreamable<G,C>... engines)Create a new cycling evolution engine with the given array ofengines.EvolutionStream<G,C>stream(EvolutionInit<G> init)EvolutionStream<G,C>stream(Supplier<EvolutionStart<G,C>> start)
-
-
-
Constructor Detail
-
CyclicEngine
public CyclicEngine(List<? extends EvolutionStreamable<G,C>> engines)
Create a new cycling evolution engine with the given list ofengines.- Parameters:
engines- the evolution engines which are part of the cycling engine- Throws:
NullPointerException- if theenginesor one of it's elements isnull
-
-
Method Detail
-
stream
public EvolutionStream<G,C> stream(Supplier<EvolutionStart<G,C>> start)
-
stream
public EvolutionStream<G,C> stream(EvolutionInit<G> init)
-
of
@SafeVarargs public static <G extends Gene<?,G>,C extends Comparable<? super C>> CyclicEngine<G,C> of(EvolutionStreamable<G,C>... engines)
Create a new cycling evolution engine with the given array ofengines.- Type Parameters:
G- the gene typeC- the fitness type- Parameters:
engines- the evolution engines which are part of the cycling engine- Returns:
- a new concatenating evolution engine
- Throws:
NullPointerException- if theenginesor one of it's elements isnull
-
-