如果没有Watchmaker程序,你将不得不创建一个实例:StandaloneEvolutionEngine。在TSP例子里,已经做好了EvolutionaryTravellingSalesman类:
private EvolutionEngine<List<String>> getEngine(CandidateFactory<List<String>> candidateFactory, EvolutionaryOperator<List<?>> pipeline, Random rng) {
return new StandaloneEvolutionEngine<List<String>>(candidateFactory, pipeline, new RouteEvaluator(distances), selectionStrategy, rng);
}
这个RouteEvaluator类适合在每一个需要评估的地方。如果我们想在hadoop机器上分类评估,我们将使用MahoutFitnessEvaluator这个评估程序,代替原来的StandaloneEvolutionEngine。我们将使用STEvolutionEngine:
private EvolutionEngine<List<String>> getEngine(CandidateFactory<List<String>> candidateFactory, EvolutionaryOperator<List<?>> pipeline, Random rng) {
MahoutFitnessEvaluator<List<String>> evaluator = new MahoutFitnessEvaluator<List<String>>(new RouteEvaluator(distances));
return new STEvolutionEngine<List<String>>(candidateFactory, pipeline, evaluator, selectionStrategy, rng);
}
瞧!你的代码已经可以运行在hadoop上了。可以运行的完整例子位于org/apache/mahout/ga/watchmaker/travellingsalesman目录