G - the gene typeC - the fitness typepublic final class CyclicEngine<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object
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)));CyclicEnginePool, you have to limit the final evolution
stream, additionally to the defined limits on the used partial engines.AdaptiveEngine,
ConcatEngine| Constructor and Description |
|---|
CyclicEngine(List<? extends EvolutionStreamable<G,C>> engines)
Create a new cycling evolution engine with the given list of
engines. |
| Modifier and Type | Method and Description |
|---|---|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(EvolutionStreamable<G,C>... engines)
Create a new cycling evolution engine with the given array of
engines. |
EvolutionStream<G,C> |
stream(EvolutionInit<G> init) |
EvolutionStream<G,C> |
stream(Supplier<EvolutionStart<G,C>> start) |
public CyclicEngine(List<? extends EvolutionStreamable<G,C>> engines)
engines.engines - the evolution engines which are part of the cycling engineNullPointerException - if the engines or one of it's
elements is nullpublic EvolutionStream<G,C> stream(Supplier<EvolutionStart<G,C>> start)
public EvolutionStream<G,C> stream(EvolutionInit<G> init)
@SafeVarargs public static <G extends Gene<?,G>,C extends Comparable<? super C>> CyclicEngine<G,C> of(EvolutionStreamable<G,C>... engines)
engines.G - the gene typeC - the fitness typeengines - the evolution engines which are part of the cycling engineNullPointerException - if the engines or one of it's
elements is null© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)