/** * 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)); }
@Test(dataProvider = "generations") public void engineGenerationLimit2(final Long generations) { final Engine<DoubleGene, Double> engine = Engine .builder(a -> a.getGene().getAllele(), DoubleChromosome.of(0, 1)) .build(); final EvolutionResult<DoubleGene, Double> result = engine .limit(() -> Limits.byFixedGeneration(generations)) .limit(() -> Limits.byFixedGeneration(Math.min(generations, 5))) .stream() .collect(EvolutionResult.toBestEvolutionResult()); Assert.assertEquals(Math.min(generations, 5), result.getTotalGenerations()); }