Example #1
0
 protected void runSolverPhases() {
   Iterator<SolverPhase> it = solverPhaseList.iterator();
   while (!termination.isSolverTerminated(solverScope) && it.hasNext()) {
     SolverPhase solverPhase = it.next();
     solverPhase.solve(solverScope);
     if (it.hasNext()) {
       solverScope.setWorkingSolutionFromBestSolution();
     }
   }
   // TODO support doing round-robin of phases (only non-construction heuristics)
 }
Example #2
0
 public void solvingEnded(DefaultSolverScope solverScope) {
   for (SolverPhase solverPhase : solverPhaseList) {
     solverPhase.solvingEnded(solverScope);
   }
   bestSolutionRecaller.solvingEnded(solverScope);
   long timeMillisSpend = solverScope.calculateTimeMillisSpend();
   if (timeMillisSpend == 0L) {
     // Avoid divide by zero exception on a fast CPU
     timeMillisSpend = 1L;
   }
   long averageCalculateCountPerSecond = solverScope.getCalculateCount() * 1000L / timeMillisSpend;
   logger.info(
       "Solving ended: time spend ({}), best score ({}), average calculate count per second ({}).",
       timeMillisSpend,
       solverScope.getBestScoreWithUninitializedPrefix(),
       averageCalculateCountPerSecond);
 }
Example #3
0
 public void solvingStarted(DefaultSolverScope solverScope) {
   if (solverScope.getBestSolution() == null) {
     throw new IllegalStateException(
         "The planningProblem must not be null." + " Use Solver.setPlanningProblem(Solution).");
   }
   solverScope.setStartingSystemTimeMillis(System.currentTimeMillis());
   solverScope.setScoreDirector(scoreDirectorFactory.buildScoreDirector());
   solverScope.setWorkingRandom(randomFactory.createRandom());
   solverScope.setWorkingSolutionFromBestSolution();
   bestSolutionRecaller.solvingStarted(solverScope);
   for (SolverPhase solverPhase : solverPhaseList) {
     solverPhase.solvingStarted(solverScope);
   }
   logger.info(
       "Solving started: time spend ({}), score ({}), new best score ({}), random ({}).",
       solverScope.calculateTimeMillisSpend(),
       solverScope.getStartingInitializedScore(),
       solverScope.getBestScore(),
       (randomFactory != null ? randomFactory : "not fixed"));
 }
Example #4
0
 public void removeSolverPhaseLifecycleListener(
     SolverPhaseLifecycleListener solverPhaseLifecycleListener) {
   for (SolverPhase solverPhase : solverPhaseList) {
     solverPhase.addSolverPhaseLifecycleListener(solverPhaseLifecycleListener);
   }
 }