Package io.jenetics.ext.engine
Class ConcatEngine<G extends Gene<?,G>,C extends Comparable<? super C>>
- java.lang.Object
- 
- io.jenetics.ext.engine.ConcatEngine<G,C>
 
- 
- Type Parameters:
- G- the gene type
- C- the fitness type
 - All Implemented Interfaces:
- EvolutionStreamable<G,C>
 
 public final class ConcatEngine<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object TheConcatEnginelets you concatenate two (or more) evolutionEngine, with different configurations, and let it use as one engineEvolutionStreamable.
 The sketch above shows how the engine concatenation works. In this example, the evolution stream of the first engine is evaluated until it terminates. The result of the first stream is then used as start input of the second evolution stream, which then delivers the final result.+----------+ +----------+ | ES | | ES | +-------+----+ | +-------+----+ | (Start) | +-----+ Start | +-----+ ------>| Engine 1 |------------>| Engine 2 |-----------> | | Result | | Result +------------+ +------------+Concatenating evolution engines might be useful, if you want to explore your search space with random search first and then start the real GA search. An essential part, when concatenating evolution engines, is to make sure your your engines are creating limited evolution streams. This is what thefinal 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 = ConcatEngine.of( engine1.limit(50), engine2.limit(() -> Limits.bySteadyFitness(30))) .stream() .collect(EvolutionResult.toBestGenotype()); System.out.println(result + ": " + problem.fitness().apply(problem.codec().decode(result)));EvolutionStreamable.limit(Supplier)andEvolutionStreamable.limit(long)methods are for. Limiting an engine means, that this engine will surely create only streams, which are limited with the predicate/generation given to the engine. If you have limited your engines, it is no longer necessary to limit your final evolution stream, but your are still able to do so.- Since:
- 4.1
- Version:
- 4.1
- See Also:
- CyclicEngine
 
- 
- 
Constructor SummaryConstructors Constructor Description ConcatEngine(List<? extends EvolutionStreamable<G,C>> engines)Create a new concatenating evolution engine with the given list of engines.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <G extends Gene<?,G>,C extends Comparable<? super C>>
 ConcatEngine<G,C>of(EvolutionStreamable<G,C>... engines)Create a new concatenating evolution engine with the given array of engines.EvolutionStream<G,C>stream(EvolutionInit<G> init)EvolutionStream<G,C>stream(Supplier<EvolutionStart<G,C>> start)
 
- 
- 
- 
Constructor Detail- 
ConcatEnginepublic ConcatEngine(List<? extends EvolutionStreamable<G,C>> engines) Create a new concatenating evolution engine with the given list of engines.- Parameters:
- engines- the engines which are concatenated to one engine
- Throws:
- NullPointerException- if the- enginesor one of it's elements is- null
 
 
- 
 - 
Method Detail- 
streampublic EvolutionStream<G,C> stream(Supplier<EvolutionStart<G,C>> start) 
 - 
streampublic EvolutionStream<G,C> stream(EvolutionInit<G> init) 
 - 
of@SafeVarargs public static <G extends Gene<?,G>,C extends Comparable<? super C>> ConcatEngine<G,C> of(EvolutionStreamable<G,C>... engines) Create a new concatenating evolution engine with the given array of engines.- Type Parameters:
- G- the gene type
- C- the fitness type
- Parameters:
- engines- the engines which are concatenated to one engine
- Returns:
- a new concatenating evolution engine
- Throws:
- NullPointerException- if the- enginesor one of it's elements is- null
 
 
- 
 
-