BitSetGrayCodeBinaryRepresentation extends BitSetBinaryRepresentation { @Override protected void encodeBinaryGenome() { BitSet grayGenome = new BitSet(this.genomeLength); int index = 0; for (int variable = 0; variable < this.descriptor.numVariables; variable++){ grayGenome.set(index, this.genome.get(index++)); for (int i = 1; i < this.descriptor.variablesLengths[variable]; i++){ grayGenome.set(index, this.genome.get(index-1) ^ this.genome.get(index++)); } } this.genome = grayGenome; } BitSetGrayCodeBinaryRepresentation(SimpleBinaryGenomeDescriptor descriptor);  BitSetGrayCodeBinaryRepresentation(BitSetGrayCodeBinaryRepresentation second); @Override Representation copy();  }
@Test public void testEncodeBinaryGenome1(){ boolean[] binary = new boolean[]{ true, false, true, false, true, false, true, false, true, true, true, true, false, false, false, true, true, false, false, true, true, false }; for (int idx = 0; idx < binary.length; idx++){ this.representation.setGeneAt(idx, binary[idx]); } boolean[] gray = new boolean[]{ true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, true, false, true, false, true, false, true }; this.representation.encodeBinaryGenome(); BitSet result = this.representation.genome; assertTrue((6+2+4+10) >= result.length()); assertEquals(binary.length, gray.length); for (int i = 0; i < binary.length; i++){ Assert.assertEquals("in step " + i, gray[i], result.get(i) ); } }