@Test(dataProvider = "limits") public void limit( final ISeq<Phenotype<DoubleGene, Double>> pop, final double geneConvergence, final double convergenceRage, final boolean proceed ) { //final ISeq<DoubleMoments> stat = GeneConvergenceLimit.statistics(pop); //stat.forEach(System.out::println); final Predicate<EvolutionResult<DoubleGene, ?>> l = Limits.byGeneConvergence(geneConvergence, convergenceRage); //System.out.println(l.test(result(pop))); Assert.assertEquals(l.test(result(pop)), proceed); }
final double convergedGeneRate ) { return byGeneConvergence( stat -> stat.getMax()*convergenceRate <= stat.getMean(), convergedGeneRate
@Test // https://github.com/jenetics/jenetics/issues/318 public void initialGeneConvergence() { RandomRegistry.using(Random32.of(() -> 234), random -> { final Problem<Double, DoubleGene, Double> problem = Problem.of( d -> 1.0, Codecs.ofScalar(DoubleRange.of(0, 1)) ); final Engine<DoubleGene, Double> engine = Engine .builder(problem) .executor(Runnable::run) .build(); final AtomicInteger count = new AtomicInteger(); final EvolutionResult<DoubleGene, Double> result = engine.stream() .limit(Limits.byGeneConvergence(0.03, 0.03)) .peek(er -> count.incrementAndGet()) .collect(EvolutionResult.toBestEvolutionResult()); Assert.assertNotNull(result); Assert.assertEquals(count.get(), 1); Assert.assertEquals(result.getTotalGenerations(), 1); Assert.assertEquals(result.getGeneration(), 1); }); }