G - the gene typeC - the fitness typepublic final class AdaptiveEngine<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements EvolutionStreamable<G,C>
AdaptiveEngine allows you to dynamically create engines with
 different configurations, depending on the last EvolutionResult of
 the previous evolution stream. It is therefore possible to increase the
 mutation probability if the population is converging to fast. The sketch
 below shows how the AdaptiveEngine is working.
  
                                           +----------+
                                           |   ES[i]  |
           +-------------------------------+------+   |
           |                                      +---+
   (Start) |  EvolutionResult[i-1] -> Engine[i]   |-----------+-->
  -----+-->|           ^                          |  Result   |
       ^   +-----------|--------------------------+           |
       |               |                                      |
       +---------------+--------------<-----------------------+
 
 
  public static void main(final String[] args) {
      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.Builder<DoubleGene, Double> builder = Engine
          .builder(problem)
          .minimizing();
      final Genotype<DoubleGene> result =
          AdaptiveEngine.<DoubleGene, Double>of(er -> engine(er, builder))
              .stream()
              .limit(Limits.bySteadyFitness(50))
              .collect(EvolutionResult.toBestGenotype());
      System.out.println(result + ": " +
          problem.fitness().apply(problem.codec().decode(result)));
  }
  private static EvolutionStreamable<DoubleGene, Double> engine(
      final EvolutionResult<DoubleGene, Double> result,
      final Engine.Builder<DoubleGene, Double> builder
  ) {
      return var(result) < 0.2
          ? builder
              .alterers(new Mutator<>(0.5))
              .build()
              .limit(5)
          : builder
              .alterers(
                  new Mutator<>(0.05),
                  new MeanAlterer<>())
              .selector(new RouletteWheelSelector<>())
              .build()
              .limit(15);
  }
  private static double var(final EvolutionResult<DoubleGene, Double> result) {
      return result != null
          ? result.getPopulation().stream()
              .map(Phenotype::getFitness)
              .collect(DoubleMoments.toDoubleMoments(Double::doubleValue))
              .getVariance()
          : 0.0;
  }ConcatEngine, 
CyclicEngine| Constructor and Description | 
|---|
| AdaptiveEngine(Function<? super EvolutionResult<G,C>,? extends EvolutionStreamable<G,C>> engine)Return a new adaptive evolution engine, with the given engine generation
 function. | 
| Modifier and Type | Method and Description | 
|---|---|
| static <G extends Gene<?,G>,C extends Comparable<? super C>> | of(Function<? super EvolutionResult<G,C>,? extends EvolutionStreamable<G,C>> engine)Return a new adaptive evolution engine, with the given engine generation
 function. | 
| EvolutionStream<G,C> | stream(EvolutionInit<G> init) | 
| EvolutionStream<G,C> | stream(Supplier<EvolutionStart<G,C>> start) | 
public AdaptiveEngine(Function<? super EvolutionResult<G,C>,? extends EvolutionStreamable<G,C>> engine)
engine - the engine generating function used for adapting the engines.NullPointerException - if the given engine is nullpublic EvolutionStream<G,C> stream(Supplier<EvolutionStart<G,C>> start)
stream in interface EvolutionStreamable<G extends Gene<?,G>,C extends Comparable<? super C>>public EvolutionStream<G,C> stream(EvolutionInit<G> init)
stream in interface EvolutionStreamable<G extends Gene<?,G>,C extends Comparable<? super C>>public static <G extends Gene<?,G>,C extends Comparable<? super C>> AdaptiveEngine<G,C> of(Function<? super EvolutionResult<G,C>,? extends EvolutionStreamable<G,C>> engine)
G - the gene typeC - the fitness typeengine - the engine generating function used for adapting the engines.
       Be aware, that the EvolutionResult for the first created
       Engine is null.NullPointerException - if the given engine is null© 2007-2018 Franz Wilhelmstötter (2018-10-28 17:23)