Beispiel #1
0
  /** Create a population of DoubleGenes */
  public static Population<DoubleGene, Double> newDoubleGenePopulation(
      final int ngenes, final int nchromosomes, final int npopulation) {
    final MSeq<DoubleChromosome> chromosomes = MSeq.ofLength(nchromosomes);

    for (int i = 0; i < nchromosomes; ++i) {
      chromosomes.set(i, DoubleChromosome.of(0, 10, ngenes));
    }

    final Genotype<DoubleGene> genotype = new Genotype<>(chromosomes.toISeq());
    final Population<DoubleGene, Double> population = new Population<>(npopulation);

    for (int i = 0; i < npopulation; ++i) {
      population.add(Phenotype.of(genotype.newInstance(), 0, FF).evaluate());
    }

    return population;
  }
Beispiel #2
0
  public static Population<EnumGene<Double>, Double> newPermutationDoubleGenePopulation(
      final int ngenes, final int nchromosomes, final int npopulation) {
    final Random random = new Random(122343);
    final MSeq<Double> alleles = MSeq.ofLength(ngenes);
    for (int i = 0; i < ngenes; ++i) {
      alleles.set(i, random.nextDouble() * 10);
    }
    final ISeq<Double> ialleles = alleles.toISeq();

    final MSeq<PermutationChromosome<Double>> chromosomes = MSeq.ofLength(nchromosomes);

    for (int i = 0; i < nchromosomes; ++i) {
      chromosomes.set(i, PermutationChromosome.of(ialleles));
    }

    final Genotype<EnumGene<Double>> genotype = new Genotype<>(chromosomes.toISeq());
    final Population<EnumGene<Double>, Double> population = new Population<>(npopulation);

    for (int i = 0; i < npopulation; ++i) {
      population.add(Phenotype.of(genotype.newInstance(), 0, PFF));
    }

    return population;
  }