Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.drools.planner.core.localsearch.decider;
 
 
Default implementation of Decider.
 
 public class DefaultDecider implements Decider {
 
     protected final transient Logger logger = LoggerFactory.getLogger(getClass());
 
 
     protected Selector selector;
     protected Acceptor acceptor;
     protected Forager forager;
 
     protected boolean assertMoveScoreIsUncorrupted = false;
     protected boolean assertUndoMoveIsUncorrupted = false;
 
     public void setLocalSearchSolverPhase(LocalSearchSolverPhase localSearchSolverPhase) {
         this. = localSearchSolverPhase;
     }
 
         return ;
     }
 
     public void setDeciderScoreComparator(DeciderScoreComparatorFactory deciderScoreComparator) {
         this. = deciderScoreComparator;
     }
 
     public void setSelector(Selector selector) {
         this. = selector;
         selector.setDecider(this);
     }
 
     public void setAcceptor(Acceptor acceptor) {
         this. = acceptor;
     }
 
     public Forager getForager() {
         return ;
     }
 
     public void setForager(Forager forager) {
         this. = forager;
     }
 
     public void setAssertMoveScoreIsUncorrupted(boolean assertMoveScoreIsUncorrupted) {
         this. = assertMoveScoreIsUncorrupted;
     }
 
     public void setAssertUndoMoveIsUncorrupted(boolean assertUndoMoveIsUncorrupted) {
         this. = assertUndoMoveIsUncorrupted;
     }
 
     // ************************************************************************
     // Worker methods
     // ************************************************************************
 
     public void phaseStarted(LocalSearchSolverPhaseScope localSearchSolverPhaseScope) {
         .phaseStarted(localSearchSolverPhaseScope);
         .phaseStarted(localSearchSolverPhaseScope);
         .phaseStarted(localSearchSolverPhaseScope);
         .phaseStarted(localSearchSolverPhaseScope);
     }
 
     public void beforeDeciding(LocalSearchStepScope localSearchStepScope) {
        .beforeDeciding(localSearchStepScope);
        .beforeDeciding(localSearchStepScope);
        .beforeDeciding(localSearchStepScope);
        .beforeDeciding(localSearchStepScope);
    }
    public void decideNextStep(LocalSearchStepScope localSearchStepScope) {
        WorkingMemory workingMemory = localSearchStepScope.getWorkingMemory();
        Iterator<MovemoveIterator = .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 (.isQuitEarly()) {
                    break;
                }
            } else {
                .trace("        Ignoring not doable move ({})."move);
            }
        }
        MoveScope pickedMoveScope = .pickMove(localSearchStepScope);
        if (pickedMoveScope != null) {
            Move step = pickedMoveScope.getMove();
            localSearchStepScope.setStep(step);
            if (.isDebugEnabled()) {
                localSearchStepScope.setStepString(step.toString());
            }
            localSearchStepScope.setUndoStep(step.createUndoMove(workingMemory));
            localSearchStepScope.setScore(pickedMoveScope.getScore());
        }
    }
    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 () {
            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());
            }
        }
        .trace("        Move score ({}), accept chance ({}) for move ({}).",
                new Object[]{moveScope.getScore(), moveScope.getAcceptChance(), moveScope.getMove()});
    }
    private void processMove(MoveScope moveScope) {
        if () {
        }
        moveScope.setScore(score);
        double acceptChance = .calculateAcceptChance(moveScope);
        moveScope.setAcceptChance(acceptChance);
        .addMove(moveScope);
    }
    public void stepDecided(LocalSearchStepScope localSearchStepScope) {
        .stepDecided(localSearchStepScope);
        .stepDecided(localSearchStepScope);
        .stepDecided(localSearchStepScope);
        .stepDecided(localSearchStepScope);
    }
    public void stepTaken(LocalSearchStepScope localSearchStepScope) {
        .stepTaken(localSearchStepScope);
        .stepTaken(localSearchStepScope);
        .stepTaken(localSearchStepScope);
        .stepTaken(localSearchStepScope);
    }
    public void phaseEnded(LocalSearchSolverPhaseScope localSearchSolverPhaseScope) {
        .phaseEnded(localSearchSolverPhaseScope);
        .phaseEnded(localSearchSolverPhaseScope);
        .phaseEnded(localSearchSolverPhaseScope);
        .phaseEnded(localSearchSolverPhaseScope);
    }
New to GrepCode? Check out our FAQ X