示例#1
0
  // Create a new and valid phenotype
  private Phenotype<G, C> newPhenotype(final long generation) {
    int count = 0;
    Phenotype<G, C> phenotype;
    do {
      phenotype =
          Phenotype.of(
              _genotypeFactory.newInstance(), generation, _fitnessFunction, _fitnessScaler);
    } while (++count < _individualCreationRetries && !_validator.test(phenotype));

    return phenotype;
  }
示例#2
0
  private EvolutionStart<G, C> evolutionStart(
      final Iterable<Genotype<G>> genotypes, final long generation) {
    final Stream<Phenotype<G, C>> stream =
        Stream.concat(
            StreamSupport.stream(genotypes.spliterator(), false)
                .map(gt -> Phenotype.of(gt, generation, _fitnessFunction, _fitnessScaler)),
            Stream.generate(() -> newPhenotype(generation)));

    final Population<G, C> population = stream.limit(getPopulationSize()).collect(toPopulation());

    return EvolutionStart.of(population, generation);
  }
 private static Phenotype<DoubleGene, Double> phenotype(final double value) {
   return Phenotype.of(
       Genotype.of(DoubleChromosome.of(DoubleGene.of(value, 0.0, 1000.0))),
       1,
       a -> a.getGene().getAllele());
 }