@Override public EvolutionStream<G, C> stream(final Supplier<EvolutionStart<G, C>> start) { return EvolutionStream.of(evolutionStart(start), this::evolve); }
/** * Return a new {@code EvolutionStreamable} instance where all created * {@code EvolutionStream}s are limited to the given number of generations. * * @param generations the number of generations after the created evolution * streams are truncated * @return a new evolution streamable object * @throws IllegalArgumentException if the given {@code generations} is * smaller than zero. */ public default EvolutionStreamable<G, C> limit(final long generations) { return limit(() -> Limits.byFixedGeneration(generations)); }
public static void main(final String[] args) { final Engine<AnyGene<Dimension>, Double> engine = Engine .builder(Squares::area, Codecs.ofScalar(Squares::nextDimension)) .build(); final Phenotype<AnyGene<Dimension>, Double> pt = engine.stream() .limit(50) .collect(EvolutionResult.toBestPhenotype()); System.out.println(pt); }
public static void main(final String[] args) { final OnesCounting problem = new OnesCounting(15, 0.13); final Engine<BitGene, Integer> engine = Engine.builder(problem).build(); final ISeq<BitGene> result = problem.codec().decoder().apply( engine.stream() .limit(10) .collect(EvolutionResult.toBestGenotype()) ); System.out.println(result); }
EvolutionResult<G, C> with(final ISeq<Phenotype<G, C>> population) { return EvolutionResult.of( getOptimize(), population, getGeneration(), getTotalGenerations(), getDurations(), getKillCount(), getInvalidCount(), getAlterCount() ); }
private Spliterator<EvolutionResult<G, C>> generate( final EvolutionInit<G> init, final EvolutionResult<G, C> result ) { return result == null ? _engine.apply(null) .stream(init) .spliterator() : _engine.apply(result) .stream(result.toEvolutionStart()) .spliterator(); }
/** * Set to a fitness maximizing strategy. * * @since 3.4 * * @return {@code this} builder, for command chaining */ public Builder<G, C> maximizing() { return optimize(Optimize.MAXIMUM); }
private static EvolutionResult<DoubleGene, Double> result( final int min, final int max, final Optimize opt ) { return EvolutionResult.of( opt, population(min, max), 1L, EvolutionDurations.ZERO, 1, 1, 1 ); }
private static EvolutionResult<DoubleGene, Double> result( final int min, final int max, final Optimize opt ) { return EvolutionResult.of( opt, population(min, max), 2L, EvolutionDurations.ZERO, 1, 1, 1 ); }
/** * Create a new {@code Knapsack} definition with the given * * @param items the basic {@link Set} of knapsack items. * @param knapsackSize the maximal knapsack size * @throws NullPointerException if the {@code items} set is {@code null} */ public Knapsack(final ISeq<Item> items, final double knapsackSize) { _codec = Codecs.ofSubSet(items); _knapsackSize = knapsackSize; }
/** * Return the double moment statistics of the buffer values. * * @return the double moment statistics of the buffer values */ public DoubleMoments doubleMoments() { return doubleMoments(_length); }
/** * Return the current evolution result object as an {@code EvolutionStart} * object with the current population and current total generation. * * @since 4.1 * * @return the current result as evolution start */ public EvolutionStart<G, C> toEvolutionStart() { return EvolutionStart.of(_population, _totalGenerations); }
/** * Return the double stream of the buffer values. * * @return the double stream of the buffer values */ public DoubleStream stream() { return stream(_length); }
/** * Return the {@link Executor} the engine is using for executing the * evolution steps. * * @return the executor used for performing the evolution steps */ public Executor getExecutor() { return _executor.get(); }
/** * Return an new timer object with the default clock implementation. * * @return a new timer */ public static Timer of() { return new Timer(System::nanoTime); }
/** * This method is an <i>alias</i> for the {@link #evolve(EvolutionStart)} * method. * * @since 3.1 */ @Override public EvolutionResult<G, C> apply(final EvolutionStart<G, C> start) { return evolve(start); }
public static void main(final String[] args) { final Engine engine = Engine .builder(MixedGenotype::fitness, ENCODING) .build(); final Phenotype best = (Phenotype)engine.stream() .limit(10) .collect(EvolutionResult.toBestPhenotype()); System.out.println(best); }
private Spliterator<EvolutionResult<G, C>> generate( final Supplier<EvolutionStart<G, C>> start, final EvolutionResult<G, C> result ) { final EvolutionStart<G, C> es = result == null ? start.get() : result.toEvolutionStart(); return _engine.apply(result) .stream(es) .spliterator(); }