Esempio n. 1
0
 public void decideNextStep(LocalSearchStepScope localSearchStepScope) {
   WorkingMemory workingMemory = localSearchStepScope.getWorkingMemory();
   Iterator<Move> moveIterator = selector.moveIterator(localSearchStepScope);
   while (moveIterator.hasNext()) {
     Move move = moveIterator.next();
     MoveScope moveScope = new MoveScope(localSearchStepScope);
     moveScope.setMove(move);
     // Filter out not doable moves
     if (move.isMoveDoable(workingMemory)) {
       doMove(moveScope);
       if (forager.isQuitEarly()) {
         break;
       }
     } else {
       logger.debug("    Ignoring not doable move ({}).", move);
     }
   }
   MoveScope pickedMoveScope = forager.pickMove(localSearchStepScope);
   if (pickedMoveScope != null) {
     Move step = pickedMoveScope.getMove();
     localSearchStepScope.setStep(step);
     if (logger.isInfoEnabled()) {
       localSearchStepScope.setStepString(step.toString());
     }
     localSearchStepScope.setUndoStep(step.createUndoMove(workingMemory));
     localSearchStepScope.setScore(pickedMoveScope.getScore());
   }
 }
Esempio n. 2
0
 private void doMove(MoveScope moveScope) {
   WorkingMemory workingMemory = moveScope.getWorkingMemory();
   Move move = moveScope.getMove();
   Move undoMove = move.createUndoMove(workingMemory);
   moveScope.setUndoMove(undoMove);
   move.doMove(workingMemory);
   processMove(moveScope);
   undoMove.doMove(workingMemory);
   if (assertUndoMoveIsUncorrupted) {
     Score undoScore =
         moveScope
             .getLocalSearchStepScope()
             .getLocalSearchSolverPhaseScope()
             .calculateScoreFromWorkingMemory();
     Score lastCompletedStepScore =
         moveScope
             .getLocalSearchStepScope()
             .getLocalSearchSolverPhaseScope()
             .getLastCompletedLocalSearchStepScope()
             .getScore();
     if (!undoScore.equals(lastCompletedStepScore)) {
       throw new IllegalStateException(
           "Corrupted undo move ("
               + undoMove
               + ") received from move ("
               + move
               + ").\n"
               + "Unequal lastCompletedStepScore ("
               + lastCompletedStepScore
               + ") and undoScore ("
               + undoScore
               + ").\n"
               + moveScope
                   .getLocalSearchStepScope()
                   .getLocalSearchSolverPhaseScope()
                   .getSolverScope()
                   .getSolutionDirector()
                   .buildConstraintOccurrenceSummary());
     }
   }
   logger.debug(
       "    Move score ({}), accept chance ({}) for move ({}).",
       new Object[] {moveScope.getScore(), moveScope.getAcceptChance(), moveScope.getMove()});
 }
 private void doMove(GreedyMoveScope moveScope) {
   WorkingMemory workingMemory = moveScope.getWorkingMemory();
   Move move = moveScope.getMove();
   Move undoMove = move.createUndoMove(workingMemory);
   moveScope.setUndoMove(undoMove);
   move.doMove(workingMemory);
   processMove(moveScope);
   undoMove.doMove(workingMemory);
   if (assertUndoMoveIsUncorrupted) {
     GreedyFitSolverPhaseScope greedyFitSolverPhaseScope =
         moveScope.getGreedyFitStepScope().getGreedyFitSolverPhaseScope();
     Score undoScore = greedyFitSolverPhaseScope.calculateScoreFromWorkingMemory();
     Score lastCompletedStepScore =
         greedyFitSolverPhaseScope.getLastCompletedStepScope().getScore();
     if (!undoScore.equals(lastCompletedStepScore)) {
       // First assert that are probably no corrupted score rules.
       greedyFitSolverPhaseScope
           .getSolverScope()
           .getSolutionDirector()
           .assertWorkingScore(undoScore);
       throw new IllegalStateException(
           "The moveClass ("
               + move.getClass()
               + ")'s move ("
               + move
               + ") probably has a corrupted undoMove ("
               + undoMove
               + ")."
               + " Or maybe there are corrupted score rules.\n"
               + "Check the Move.createUndoMove(...) method of that Move class"
               + " and enable EnvironmentMode TRACE to fail-faster on corrupted score rules.\n"
               + "Score corruption: the lastCompletedStepScore ("
               + lastCompletedStepScore
               + ") is not the undoScore ("
               + undoScore
               + ").");
     }
   }
   logger.trace(
       "        Move score ({}) for move ({}).",
       new Object[] {moveScope.getScore(), moveScope.getMove()});
 }