Ejemplo n.º 1
0
 protected Solution buildAndSolve(
     SolverFactory solverFactory,
     EnvironmentMode environmentMode,
     Solution planningProblem,
     long maximumMinutesSpend) {
   solverFactory
       .getSolverConfig()
       .getTerminationConfig()
       .setMaximumMinutesSpend(maximumMinutesSpend);
   SolverConfig solverConfig = solverFactory.getSolverConfig();
   solverConfig.setEnvironmentMode(environmentMode);
   ScoreDirectorFactoryConfig assertionScoreDirectorFactory =
       createOverwritingAssertionScoreDirectorFactory();
   if (assertionScoreDirectorFactory != null && environmentMode.isAsserted()) {
     solverConfig
         .getScoreDirectorFactoryConfig()
         .setAssertionScoreDirectorFactory(assertionScoreDirectorFactory);
   }
   Solver solver = solverFactory.buildSolver();
   solver.setPlanningProblem(planningProblem);
   solver.solve();
   Solution bestSolution = solver.getBestSolution();
   if (bestSolution == null) {
     // Solver didn't make it past initialization // TODO remove me once getBestSolution() never
     // returns null
     bestSolution = planningProblem;
   }
   return bestSolution;
 }
  @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());
  }
Ejemplo n.º 3
0
 @Override
 protected Solver createSolver() {
   SolverFactory solverFactory = SolverFactory.createFromXmlResource(SOLVER_CONFIG);
   return solverFactory.buildSolver();
 }
 public VehicleRoutingDistanceTypeComparison() {
   vehicleRoutingDao = new VehicleRoutingDao();
   SolverFactory solverFactory =
       SolverFactory.createFromXmlResource(VehicleRoutingApp.SOLVER_CONFIG);
   scoreDirectorFactory = solverFactory.buildSolver().getScoreDirectorFactory();
 }
Ejemplo n.º 5
0
 @Override
 protected Solver<CloudBalance> createSolver() {
   SolverFactory<CloudBalance> solverFactory = SolverFactory.createFromXmlResource(SOLVER_CONFIG);
   return solverFactory.buildSolver();
 }