@Test public void testCreate() { LongChromosome c1 = LongChromosome.of(0, 100, 10); LongChromosome c2 = LongChromosome.of(0, 100, 10); Genotype<LongGene> g1 = Genotype.of(c1, c2); Genotype<LongGene> g2 = g1.newInstance(); assertNotSame(g1, g2); assertNotEquals(g1, g2); }
@Test public void newInstance() { final Genotype<DoubleGene> gt1 = Genotype.of( //Rotation DoubleChromosome.of(DoubleGene.of(-Math.PI, Math.PI)), //Translation DoubleChromosome.of(DoubleGene.of(-300, 300), DoubleGene.of(-300, 300)), //Shear DoubleChromosome.of(DoubleGene.of(-0.5, 0.5), DoubleGene.of(-0.5, 0.5)) ); final Genotype<DoubleGene> gt2 = gt1.newInstance(); Assert.assertEquals(gt1.length(), gt2.length()); for (int i = 0; i < gt1.length(); ++i) { Chromosome<DoubleGene> ch1 = gt1.getChromosome(i); Chromosome<DoubleGene> ch2 = gt2.getChromosome(i); Assert.assertEquals(ch1.length(), ch2.length()); } }
public static ISeq<Phenotype<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 MSeq<Phenotype<EnumGene<Double>, Double>> population = MSeq.ofLength(npopulation); for (int i = 0; i < npopulation; ++i) { population.set(i, Phenotype.of(genotype.newInstance(), 0, PFF)); } return population.toISeq(); }
public static ISeq<Phenotype<DoubleGene, Double>> population( 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 MSeq<Phenotype<DoubleGene, Double>> population = MSeq.ofLength(npopulation); for (int i = 0; i < npopulation; ++i) { population.set(i, Phenotype.of(genotype.newInstance(), 0, TestUtils.FF)); } return population.toISeq(); }
/** * Create a population of DoubleGenes */ public static ISeq<Phenotype<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 MSeq<Phenotype<DoubleGene, Double>> population = MSeq.ofLength(npopulation); for (int i = 0; i < npopulation; ++i) { population.set(i, Phenotype.of(genotype.newInstance(), 0, FF).evaluate()); } return population.toISeq(); }