@Test public void survivorsFraction() { final Function<Genotype<DoubleGene>, Double> fitnessFunction = gt -> gt.getGene().getAllele(); final Factory<Genotype<DoubleGene>> genotypeFactory = Genotype.of(DoubleChromosome.of(0, 1)); final Engine<DoubleGene, Double> engine = Engine .builder(fitnessFunction, genotypeFactory) .survivorsFraction(0.3) .build(); Assert.assertEquals(engine.getSurvivorsCount(), 15); Assert.assertEquals(engine.getOffspringCount(), 35); }
@Test public void offspringSize() { final Function<Genotype<DoubleGene>, Double> fitnessFunction = gt -> gt.getGene().getAllele(); final Factory<Genotype<DoubleGene>> genotypeFactory = Genotype.of(DoubleChromosome.of(0, 1)); final Engine<DoubleGene, Double> engine = Engine .builder(fitnessFunction, genotypeFactory) .offspringSize(35) .build(); Assert.assertEquals(engine.getSurvivorsCount(), 15); Assert.assertEquals(engine.getOffspringCount(), 35); }
@Test public void survivorsSize() { final Function<Genotype<DoubleGene>, Double> fitnessFunction = gt -> gt.getGene().getAllele(); final Factory<Genotype<DoubleGene>> genotypeFactory = Genotype.of(DoubleChromosome.of(0, 1)); final Engine<DoubleGene, Double> engine = Engine .builder(fitnessFunction, genotypeFactory) .survivorsSize(15) .build(); Assert.assertEquals(engine.getSurvivorsCount(), 15); Assert.assertEquals(engine.getOffspringCount(), 35); }
Assert.assertEquals(engine.getOptimize(), optimize); Assert.assertEquals(engine.getOffspringCount(), (int)(offspringFraction*populationSize)); Assert.assertEquals(engine.getOffspringCount() + engine.getSurvivorsCount(), populationSize); Assert.assertEquals(engine.getPopulationSize(), populationSize); Assert.assertEquals(engine.getMaximalPhenotypeAge(), phenotypeAge);