return solverFactory.buildSolver();
}
protected Solver createSolverByApi() {
// Not recommended! It is highly recommended to use XmlSolverFactory with an XML configuration instead.
SolverConfig solverConfig = new SolverConfig();
solverConfig.setSolutionClass(NQueens.class);
Set<Class<?>> planningEntityClassSet = new HashSet<Class<?>>();
planningEntityClassSet.add(Queen.class);
solverConfig.setPlanningEntityClassSet(planningEntityClassSet);
ScoreDirectorFactoryConfig scoreDirectorFactoryConfig = solverConfig.getScoreDirectorFactoryConfig();
scoreDirectorFactoryConfig.setScoreDefinitionType(ScoreDirectorFactoryConfig.ScoreDefinitionType.SIMPLE);
scoreDirectorFactoryConfig.setScoreDrlList(
Arrays.asList("/org/drools/planner/examples/nqueens/solver/nQueensScoreRules.drl"));
TerminationConfig terminationConfig = solverConfig.getTerminationConfig();
terminationConfig.setScoreAttained("0");
List<SolverPhaseConfig> solverPhaseConfigList = new ArrayList<SolverPhaseConfig>();
ConstructionHeuristicSolverPhaseConfig constructionHeuristicSolverPhaseConfig
= new ConstructionHeuristicSolverPhaseConfig();
constructionHeuristicSolverPhaseConfig.setConstructionHeuristicType(
ConstructionHeuristicSolverPhaseConfig.ConstructionHeuristicType.FIRST_FIT_DECREASING);
constructionHeuristicSolverPhaseConfig.setConstructionHeuristicPickEarlyType(
ConstructionHeuristicPickEarlyType.FIRST_LAST_STEP_SCORE_EQUAL_OR_IMPROVING);
solverPhaseConfigList.add(constructionHeuristicSolverPhaseConfig);
LocalSearchSolverPhaseConfig localSearchSolverPhaseConfig = new LocalSearchSolverPhaseConfig();
ChangeMoveSelectorConfig changeMoveSelectorConfig = new ChangeMoveSelectorConfig();
changeMoveSelectorConfig.setSelectionOrder(SelectionOrder.ORIGINAL);
localSearchSolverPhaseConfig.setMoveSelectorConfigList(
Arrays.<MoveSelectorConfig>asList(changeMoveSelectorConfig));
localSearchSolverPhaseConfig.getAcceptorConfig().setSolutionTabuSize(1000);
solverPhaseConfigList.add(localSearchSolverPhaseConfig);
solverConfig.setSolverPhaseConfigList(solverPhaseConfigList);
return solverConfig.buildSolver();
}