ParallelFunctionEvaluator implements FunctionEvaluator { protected PositionDescriptor getIndexForIndividual(Population[] populations, int individualIdx){ for (int i = 0; i < populations.length; i++){ Individual[] individuals = populations[i].getIndividuals(); if (individuals.length > individualIdx ){ return new PositionDescriptor(i, individualIdx); } else { individualIdx -= individuals.length; } } return new PositionDescriptor(populations.length-1, populations[populations.length-1].getIndividuals().length-1); } ParallelFunctionEvaluator();  ParallelFunctionEvaluator(int numThreads); synchronized void evaluate(Population[] populations, Function function);  }
@Test public void testGetIndexForIndividual() throws Exception { ParallelFunctionEvaluator evaluator = new ParallelFunctionEvaluator(); Population[] populations = new Population[]{new SimplePopulation(new Individual[6]), new SimplePopulation(new Individual[4]), new SimplePopulation(new Individual[3])}; ParallelFunctionEvaluator.PositionDescriptor descriptor = evaluator.getIndexForIndividual(populations, 7); assertEquals(1, descriptor.getPopulationIndex()); assertEquals(1, descriptor.getIndividualIndex()); descriptor = evaluator.getIndexForIndividual(populations, 0); assertEquals(0, descriptor.getPopulationIndex()); assertEquals(0, descriptor.getIndividualIndex()); descriptor = evaluator.getIndexForIndividual(populations, 1); assertEquals(0, descriptor.getPopulationIndex()); assertEquals(1, descriptor.getIndividualIndex()); descriptor = evaluator.getIndexForIndividual(populations, 6); assertEquals(1, descriptor.getPopulationIndex()); assertEquals(0, descriptor.getIndividualIndex()); descriptor = evaluator.getIndexForIndividual(populations, 9); assertEquals(1, descriptor.getPopulationIndex()); assertEquals(3, descriptor.getIndividualIndex()); descriptor = evaluator.getIndexForIndividual(populations, 10); assertEquals(2, descriptor.getPopulationIndex()); assertEquals(0, descriptor.getIndividualIndex()); descriptor = evaluator.getIndexForIndividual(populations, 12); assertEquals(2, descriptor.getPopulationIndex()); assertEquals(2, descriptor.getIndividualIndex()); descriptor = evaluator.getIndexForIndividual(populations, 14); assertEquals(2, descriptor.getPopulationIndex()); assertEquals(2, descriptor.getIndividualIndex()); }