SimpleGenotypeRepresentationFactory extends AbstractGenotypeRepresentationFactory { public void setFunction(ObjectiveFunction function) { this.function = function; this.descriptor.setNumVariables(function.getDimension()); this.descriptor.setVariablesLowerBounds(function.getMinimum()); this.descriptor.setVariablesLengths(new int[function.getDimension()]); this.descriptor.setVariablesPrecisions(new double[function.getDimension()]); switch (this.encodingType){ case FixedLength: processFixedLengthEncoding(); break; case FixedPrecision: processFixedPrecisionEncoding(); break; } } SimpleGenotypeRepresentationFactory(); Representation createRepresentation(double[] position); void setFunction(ObjectiveFunction function); Class<? extends Representation> getRepresentationType(); CodeType getCodeType(); void setCodeType(CodeType codeType);  }
@Test public void testSetFunction1() throws Exception { this.factory.setEncodingType(EncodingType.FixedLength); this.factory.setFixedPrecision(0.1); this.factory.setFixedLength(16); this.factory.setFunction(this.function); SimpleBinaryGenomeDescriptor descriptor = this.factory.descriptor; assertEquals(function.getDimension(), descriptor.getNumVariables()); Assert.assertArrayEquals(function.getMinimum(), descriptor.getVariablesLowerBounds(), 0.0); Assert.assertArrayEquals(new int[]{16, 16, 16}, descriptor.getVariablesLengths()); for (int i = 0; i < 3; i++){ assertTrue(this.function.getMaximum()[i] <= Math.pow(2, 16)*descriptor.getVariablesPrecisions()[i]); } assertEquals(0.000152590219, descriptor.getVariablesPrecisions()[0], 0.000000000001); assertEquals(1525902.19, descriptor.getVariablesPrecisions()[1], 0.01); assertEquals(1.068131E97, descriptor.getVariablesPrecisions()[2], 0.0001E97); }
@Test public void testSetFunction2() throws Exception { this.factory.setEncodingType(EncodingType.FixedPrecision); this.factory.setFixedPrecision(1.0); this.factory.setFixedLength(16); this.factory.setFunction(this.function); SimpleBinaryGenomeDescriptor descriptor = this.factory.descriptor; assertEquals(function.getDimension(), descriptor.getNumVariables()); Assert.assertArrayEquals(function.getMinimum(), descriptor.getVariablesLowerBounds(), 0.0); Assert.assertArrayEquals(new int[]{4, 37, 339}, descriptor.getVariablesLengths()); Assert.assertArrayEquals(new double[]{1, 1, 1}, descriptor.getVariablesPrecisions(), 0.00000000001); }