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 type
C - the fitness type
All Implemented Interfaces:
EvolutionStreamable<G,C>

public final class CyclicEngine<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object
The CyclicEngine lets you concatenate two (or more) evolution Engine, with different configurations, and let it use as one engine EvolutionStreamable. If the last evolution stream terminates, it's final result is fed back to first engine.
 
                  +----------+               +----------+
                  |       ES |               |       ES |
          +------------+     |       +------------+     |
  (Start) |            |-----+ Start |            |-----+
 ---+---->|  Engine 1  |------------>|  Engine 2  | --------+
    ^     |            | Result      |            |         |
    |     +------------+             +------------+         |
    |                                                       |
    +------------------------------<------------------------+
                              Result
 
The CyclicEngine allows to do an broad search-fine search-cycle as long as you want.
final 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)));
When using a 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:
  • Constructor Details

    • CyclicEngine

      public CyclicEngine(List<? extends EvolutionStreamable<G,C>> engines)
      Create a new cycling evolution engine with the given list of engines.
      Parameters:
      engines - the evolution engines which are part of the cycling engine
      Throws:
      NullPointerException - if the engines or one of its elements is null
  • Method Details

    • stream

      Description copied from interface: EvolutionStreamable
      Create a new, possibly infinite, evolution stream with the given evolution start. If an empty Population 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
    • stream

      Description copied from interface: EvolutionStreamable
      Create a new, possibly infinite, evolution stream with the given initial value. If an empty Population 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
    • 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 of engines.
      Type Parameters:
      G - the gene type
      C - the fitness type
      Parameters:
      engines - the evolution engines which are part of the cycling engine
      Returns:
      a new concatenating evolution engine
      Throws:
      NullPointerException - if the engines or one of it's elements is null