コード例 #1
0
  @Test
  public void trackLocalSearch() {
    SolverFactory<NQueens> solverFactory =
        SolverFactory.createFromXmlResource(NQueensApp.SOLVER_CONFIG);
    SolverConfig solverConfig = solverFactory.getSolverConfig();

    NQueensGenerator generator = new NQueensGenerator();
    NQueens planningProblem = NQueensSolutionInitializer.initialize(generator.createNQueens(N));

    LocalSearchPhaseConfig localSearchPhaseConfig = new LocalSearchPhaseConfig();
    localSearchPhaseConfig.setAcceptorConfig(acceptorConfig);
    localSearchPhaseConfig.setForagerConfig(localSearchForagerConfig);
    localSearchPhaseConfig.getForagerConfig().setBreakTieRandomly(false);
    localSearchPhaseConfig.setMoveSelectorConfig(new ChangeMoveSelectorConfig());
    localSearchPhaseConfig.getMoveSelectorConfig().setSelectionOrder(SelectionOrder.ORIGINAL);
    localSearchPhaseConfig.setTerminationConfig(new TerminationConfig());
    localSearchPhaseConfig.getTerminationConfig().setStepCountLimit(20);
    solverConfig.getPhaseConfigList().set(1, localSearchPhaseConfig);

    NQueensStepTracker listener = new NQueensStepTracker();
    DefaultSolver<NQueens> solver = (DefaultSolver<NQueens>) solverFactory.buildSolver();
    solver.addPhaseLifecycleListener(listener);
    NQueens bestSolution = solver.solve(planningProblem);

    assertNotNull(bestSolution);
    assertTrackingList(expectedCoordinates, listener.getTrackingList());
  }