MahoutEvaluator { public static void evaluate(FitnessEvaluator<?> evaluator, Iterable<?> population, Collection<Double> evaluations, Path input, Path output) throws IOException, ClassNotFoundException, InterruptedException { Job job = new Job(); job.setJarByClass(MahoutEvaluator.class); Configuration conf = job.getConfiguration(); FileSystem fs = FileSystem.get(conf); HadoopUtil.delete(conf, input); HadoopUtil.delete(conf, output); storePopulation(fs, new Path(input, "population"), population); configureJob(job, conf, evaluator, input, output); job.waitForCompletion(true); OutputUtils.importEvaluations(fs, conf, output, evaluations); } private  MahoutEvaluator(); static void evaluate(FitnessEvaluator<?> evaluator,
                              Iterable<?> population,
                              Collection<Double> evaluations,
                              Path input,
                              Path output);  }
@Test public void testEvaluate() throws Exception { List<DummyCandidate> population = DummyCandidate.generatePopulation(POPULATION_SIZE); DummyEvaluator.clearEvaluations(); FitnessEvaluator<DummyCandidate> evaluator = new DummyEvaluator(); List<Double> results = new ArrayList<Double>(); Path input = getTestTempDirPath("input"); Path output = getTestTempDirPath("output"); MahoutEvaluator.evaluate(evaluator, population, results, input, output); assertEquals("Number of evaluations", POPULATION_SIZE, results.size()); for (int index = 0; index < population.size(); index++) { DummyCandidate candidate = population.get(index); assertEquals("Evaluation of the candidate " + index, DummyEvaluator.getFitness(candidate.getIndex()), results.get(index), EPSILON); } }
@Test public void testEvaluate() throws Exception { List<DummyCandidate> population = DummyCandidate.generatePopulation(POPULATION_SIZE); DummyEvaluator.clearEvaluations(); FitnessEvaluator<DummyCandidate> evaluator = new DummyEvaluator(); List<Double> results = Lists.newArrayList(); Path input = getTestTempDirPath("input"); Path output = getTestTempDirPath("output"); MahoutEvaluator.evaluate(evaluator, population, results, input, output); assertEquals("Number of evaluations", POPULATION_SIZE, results.size()); for (int index = 0; index < population.size(); index++) { DummyCandidate candidate = population.get(index); assertEquals("Evaluation of the candidate " + index, DummyEvaluator.getFitness(candidate.getIndex()), results.get(index), EPSILON); } }