private static double fitness(final Genotype gt) { final DoubleChromosome dc = (DoubleChromosome)gt.getChromosome(0); final BitChromosome bc = (BitChromosome)gt.getChromosome(1); final IntegerChromosome ic = (IntegerChromosome)gt.getChromosome(2); return dc.doubleValue() + bc.bitCount() + ic.doubleValue(); }
private static Integer count(final Genotype<BitGene> gt) { return gt.getChromosome() .as(BitChromosome.class) .bitCount(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void selectNegativeCountArgument() { final Factory<Genotype<DoubleGene>> gtf = Genotype.of(DoubleChromosome.of(0.0, 1.0)); final MSeq<Phenotype<DoubleGene, Double>> population = MSeq.ofLength(2); for (int i = 0, n = 2; i < n; ++i) { population.set(i, Phenotype.of(gtf.newInstance(), 12, TestUtils.FF)); } selector().select(population.toISeq(), -1, Optimize.MAXIMUM); }
@Override public Codec<ISeq<BitGene>, BitGene> codec() { return Codec.of( Genotype.of(BitChromosome.of(_length, _onesProbability)), gt -> gt.getChromosome().toSeq() ); }
private static Integer count(final Genotype<BitGene> gt) { return ((BitChromosome)gt.getChromosome()).bitCount(); }
/** * Create a new, <em>random</em> chromosome. */ @Override public CharacterChromosome newInstance() { return of(_validCharacters, lengthRange()); }
/** * Create a new chromosome with the {@link CharacterGene#DEFAULT_CHARACTERS} * char set as valid characters. * * @param length the {@code length} of the new chromosome. * @return a new {@code CharacterChromosome} with the given parameter * @throws IllegalArgumentException if the {@code length} is smaller than * one. */ public static CharacterChromosome of(final int length) { return of(DEFAULT_CHARACTERS, length); }
@Override public Chromosome<AnyGene<A>> newInstance(final ISeq<AnyGene<A>> genes) { return new AnyChromosome<>( genes, _supplier, _alleleValidator, _alleleSeqValidator, lengthRange() ); }
/** * @throws NullPointerException if the given gene array is {@code null}. */ @Override public CharacterChromosome newInstance(final ISeq<CharacterGene> genes) { return new CharacterChromosome(genes, lengthRange()); }
@Test(expectedExceptions = NullPointerException.class) public void selectNullOptimizeArgument() { final Factory<Genotype<DoubleGene>> gtf = Genotype.of(DoubleChromosome.of(0.0, 1.0)); final MSeq<Phenotype<DoubleGene, Double>> population = MSeq.ofLength(2); for (int i = 0, n = 2; i < n; ++i) { population.set(i, Phenotype.of(gtf.newInstance(), 12, TestUtils.FF)); } selector().select(population.toISeq(), 1, null); }