EuclideanDistanceFunction implements DistanceFunction { public double distance(Individual firstIndividual, Individual secondIndividual) { double[] first = firstIndividual.getRepresentation().getDoubleValue(); double[] second = secondIndividual.getRepresentation().getDoubleValue(); double distance = 0.0; double ba; for (int i = 0; i < first.length; i++){ ba = second[i] - first[i]; distance += ba * ba; } return Math.sqrt(distance); }  double distance(Individual firstIndividual, Individual secondIndividual); Class<? extends Representation> getAcceptableType();  }
@Test public void testDistance() throws Exception { Representation repr1 = new SimplePhenotypeRepresentation(); repr1.setDoubleValue(new double[]{1.0, 2.3, 5.6, 1000.4}); Individual ind1 = new SimpleIndividual(0, 0.0, repr1); Representation repr2 = new SimplePhenotypeRepresentation(); repr2.setDoubleValue(new double[]{13.6, 10004.5, -11.5, -666.7}); Individual ind2 = new SimpleIndividual(0, 0.0, repr2); double distance1 = this.function.distance(ind1, ind2); assertEquals(10140.2011, distance1, 0.0001); double distance2 = this.function.distance(ind2, ind1); assertEquals(10140.2011, distance2, 0.0001); distance1 = this.function.distance(ind1, ind1); assertTrue(distance1 == 0.0); }