SimpleFunctionEvaluator implements FunctionEvaluator { public void evaluate(Population[] populations, Function function) { if (populations != null && function != null){ for (Population population : populations){ if (population.getIndividuals() != null){ for (Individual individual : population.getIndividuals()){ if (individual.getRepresentation() != null){ individual.setValue(function.valueAt(individual.getCurrentPosition())); } } } } } }  void evaluate(Population[] populations, Function function);  }
@Test public void testEvaluate1() throws Exception { DeJongParabolaFunction function = new DeJongParabolaFunction(); function.setDimension(2); function.setOffset(0.0); function.setInverted(false); SimpleIndividual ind1 = new SimpleIndividual(1, 0.0, new SimplePhenotypeRepresentation(new double[]{1.0, 2.0})); SimpleIndividual ind2 = new SimpleIndividual(1, 0.0, new SimplePhenotypeRepresentation(new double[]{-2.0, 2.0})); SimpleIndividual ind3 = new SimpleIndividual(1, 0.0, new SimplePhenotypeRepresentation(new double[]{-3.0, -2.0})); SimpleIndividual ind4 = new SimpleIndividual(1, 0.0, new SimplePhenotypeRepresentation(new double[]{1.0, -3.0})); ind1.setValue(0.0); ind2.setValue(0.0); ind3.setValue(0.0); ind4.setValue(0.0); Individual[] individuals = new Individual[]{ind1, ind2, ind3, ind4}; Population[] populations = new Population[]{new SimplePopulation(individuals)}; SimpleFunctionEvaluator evaluator = new SimpleFunctionEvaluator(); evaluator.evaluate(populations, function); assertEquals(5.0, ind1.getValue(), 0.0); assertEquals(8.0, ind2.getValue(), 0.0); assertEquals(13.0, ind3.getValue(), 0.0); assertEquals(10.0, ind4.getValue(), 0.0); }