private EvolutionResult<G, C> withTotalGenerations(final long total) { return of( _optimize, _population, _generation, total, _durations, _killCount, _invalidCount, _alterCount ); }
private static EvolutionResult<DoubleGene, Double> result( final ISeq<Phenotype<DoubleGene, Double>> pop ) { return EvolutionResult.of( Optimize.MAXIMUM, pop, 3L, 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), 1L, EvolutionDurations.ZERO, 1, 1, 1 ); }
private static EvolutionResult<DoubleGene, Double> result( final int min, final int max, final int generation, final Optimize opt ) { return EvolutionResult.of( opt, population(min, max), generation, 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 ); }
private EvolutionResult<IntegerGene, Integer> result(final ISeq<Genotype<IntegerGene>> genotypes) { return EvolutionResult.of( Optimize.MAXIMUM, genotypes.map(gt -> Phenotype.of(gt, 1, Genotype::length)), 8, 2, EvolutionDurations.ZERO, 3, 4, 5 ); }
EvolutionResult<G, C> with(final ISeq<Phenotype<G, C>> population) { return EvolutionResult.of( getOptimize(), population, getGeneration(), getTotalGenerations(), getDurations(), getKillCount(), getInvalidCount(), getAlterCount() ); }
private static EvolutionStream<DoubleGene, Double> stream() { final Function<EvolutionStart<DoubleGene, Double>, EvolutionResult<DoubleGene, Double>> ff = s -> EvolutionResult.of( Optimize.MAXIMUM, ISeq.empty(), 1, EvolutionDurations.ZERO, 0, 0, 0 ); return new EvolutionStreamImpl<DoubleGene, Double>( () -> EvolutionStart.of(ISeq.empty(), 1), ff ); }
@Test public void bestWorstPhenotype() { final int length = 100; final Function<Genotype<IntegerGene>, Integer> ff = gt -> gt.getGene().getAllele(); final MSeq<Phenotype<IntegerGene, Integer>> population = MSeq.ofLength(length); for (int i = 0; i < length; ++i) { final Genotype<IntegerGene> gt = Genotype.of(IntegerChromosome.of( IntegerGene.of(i, 0, length) )); population.set(i, Phenotype.of(gt, 1, ff)); } population.shuffle(RandomRegistry.getRandom()); final EvolutionResult<IntegerGene, Integer> maxResult = EvolutionResult.of( Optimize.MAXIMUM, population.toISeq(), 0, 0, EvolutionDurations.ZERO, 0, 0, 0 ); Assert.assertEquals(maxResult.getBestFitness().intValue(), length - 1); Assert.assertEquals(maxResult.getWorstFitness().intValue(), 0); final EvolutionResult<IntegerGene, Integer> minResult = EvolutionResult.of( Optimize.MINIMUM, population.toISeq(), 0, 0, EvolutionDurations.ZERO, 0, 0, 0 ); Assert.assertEquals(minResult.getBestFitness().intValue(), 0); Assert.assertEquals(minResult.getWorstFitness().intValue(), length - 1); }
EvolutionResult.of( _optimize, result.result,
final EvolutionResult<IntegerGene, Integer> smallMaxResult = EvolutionResult.of( Optimize.MAXIMUM, small.toISeq(), 0, 0, EvolutionDurations.ZERO, 0, 0, 0 ); final EvolutionResult<IntegerGene, Integer> bigMaxResult = EvolutionResult.of( Optimize.MAXIMUM, big.toISeq(), 0, 0, EvolutionDurations.ZERO, 0, 0, 0 final EvolutionResult<IntegerGene, Integer> smallMinResult = EvolutionResult.of( Optimize.MINIMUM, small.toISeq(), 0, 0, EvolutionDurations.ZERO, 0, 0, 0 ); final EvolutionResult<IntegerGene, Integer> bigMinResult = EvolutionResult.of( Optimize.MINIMUM, big.toISeq(), 0, 0, EvolutionDurations.ZERO, 0, 0, 0
public static EvolutionResult<IntegerGene, Integer> result(final int value) { final Genotype<IntegerGene> genotype = Genotype.of( IntegerChromosome.of( IntegerGene.of(value, 0, Integer.MAX_VALUE) ) ); return EvolutionResult.<IntegerGene, Integer>of( Optimize.MINIMUM, ISeq.of(Phenotype.of(genotype, 1, gt -> gt.getGene().getAllele())), 1, 1, EvolutionDurations.ZERO, 1, 1, 1 ); }
private static EvolutionResult<IntegerGene, Integer> newResult( final Optimize opt, final int value ) { final int length = 1000; final Function<Genotype<IntegerGene>, Integer> ff = gt -> gt.getGene().getAllele(); final MSeq<Phenotype<IntegerGene, Integer>> pop = MSeq.ofLength(length); for (int i = 0; i < length; ++i) { final Genotype<IntegerGene> gt = Genotype.of(IntegerChromosome.of( IntegerGene.of(value, 0, length) )); pop.set(i, Phenotype.of(gt, 1, ff)); } pop.shuffle(RandomRegistry.getRandom()); return EvolutionResult .of(opt, pop.toISeq(), 0, 0, EvolutionDurations.ZERO, 0, 0, 0); }