private Supplier<EvolutionStart<G, C>> evolutionStart(final Supplier<EvolutionStart<G, C>> start) { return () -> { final EvolutionStart<G, C> es = start.get(); final ISeq<Phenotype<G, C>> population = es.getPopulation(); final long generation = es.getGeneration(); final Stream<Phenotype<G, C>> stream = Stream.concat( population.stream().map(this::toFixedPhenotype), Stream.generate(() -> newPhenotype(generation)) ); final ISeq<Phenotype<G, C>> pop = stream .limit(getPopulationSize()) .collect(ISeq.toISeq()); return EvolutionStart.of(pop, generation); }; }
/** * Create a new evolution {@code Engine.Builder} initialized with the values * of the current evolution {@code Engine}. With this method, the evolution * engine can serve as a template for a new one. * * @return a new engine builder */ public Builder<G, C> builder() { return new Builder<G, C>(_genotypeFactory, _fitnessFunction) .alterers(_alterer) .clock(_clock) .evaluator(_evaluator) .executor(_executor.get()) .fitnessScaler(_fitnessScaler) .maximalPhenotypeAge(_maximalPhenotypeAge) .offspringFraction((double)_offspringCount/(double)getPopulationSize()) .offspringSelector(_offspringSelector) .optimize(_optimize) .phenotypeValidator(_validator) .populationSize(getPopulationSize()) .survivorsSelector(_survivorsSelector) .individualCreationRetries(_individualCreationRetries) .mapping(_mapper); }
Assert.assertEquals(engine.getOffspringCount(), (int)(offspringFraction*populationSize)); Assert.assertEquals(engine.getOffspringCount() + engine.getSurvivorsCount(), populationSize); Assert.assertEquals(engine.getPopulationSize(), populationSize); Assert.assertEquals(engine.getMaximalPhenotypeAge(), phenotypeAge);