private static Integer count(final Genotype<BitGene> gt) { return ((BitChromosome)gt.getChromosome()).bitCount(); }
private static Integer count(final Genotype<BitGene> gt) { return gt.getChromosome() .as(BitChromosome.class) .bitCount(); }
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(); }
@Test public void ones() { final BitChromosome c = BitChromosome.of(1000, 0.5); final int ones = (int)c.ones().count(); assertEquals(ones, c.bitCount()); assertTrue(c.ones().allMatch(c::booleanValue)); }
@Test public void zeros() { final BitChromosome c = BitChromosome.of(1000, 0.5); final int zeros = (int)c.zeros().count(); assertEquals(zeros, c.length() - c.bitCount()); assertTrue(c.zeros().noneMatch(c::booleanValue)); }