Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2011 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;
 
Default implementation of LocalSearchSolverPhase.
 
 
     protected Decider decider;
 
     protected boolean assertStepScoreIsUncorrupted = false;
 
     public void setDecider(Decider decider) {
         this. = decider;
         this..setLocalSearchSolverPhase(this);
     }
 
     public void setAssertStepScoreIsUncorrupted(boolean assertStepScoreIsUncorrupted) {
         this. = assertStepScoreIsUncorrupted;
     }
 
     // ************************************************************************
     // Worker methods
     // ************************************************************************
 
     public void solve(DefaultSolverScope solverScope) {
         LocalSearchSolverPhaseScope localSearchSolverPhaseScope = new LocalSearchSolverPhaseScope(solverScope);
         phaseStarted(localSearchSolverPhaseScope);
 
         LocalSearchStepScope localSearchStepScope = createNextStepScope(localSearchSolverPhaseScopenull);
         while (!.isPhaseTerminated(localSearchSolverPhaseScope)) {
             localSearchStepScope.setTimeGradient(.calculatePhaseTimeGradient(localSearchSolverPhaseScope));
             beforeDeciding(localSearchStepScope);
             .decideNextStep(localSearchStepScope);
             Move nextStep = localSearchStepScope.getStep();
             if (nextStep == null) {
                 // TODO JBRULES-2213 do not terminate, but warn and try again
                 .warn("No move accepted for step index ({}) out of {} accepted moves. Terminating by exception.",
                         localSearchStepScope.getStepIndex(), .getForager().getAcceptedMovesSize());
                 break;
             }
             stepDecided(localSearchStepScope);
             nextStep.doMove(localSearchStepScope.getWorkingMemory());
             // there is no need to recalculate the score, but we still need to set it
             localSearchSolverPhaseScope.getWorkingSolution().setScore(localSearchStepScope.getScore());
             if () {
                 localSearchSolverPhaseScope.assertWorkingScore(localSearchStepScope.getScore());
             }
             stepTaken(localSearchStepScope);
             localSearchStepScope = createNextStepScope(localSearchSolverPhaseScopelocalSearchStepScope);
         }
         phaseEnded(localSearchSolverPhaseScope);
     }
 
     private LocalSearchStepScope createNextStepScope(LocalSearchSolverPhaseScope localSearchSolverPhaseScopeLocalSearchStepScope completedLocalSearchStepScope) {
         if (completedLocalSearchStepScope == null) {
             completedLocalSearchStepScope = new LocalSearchStepScope(localSearchSolverPhaseScope);
             completedLocalSearchStepScope.setScore(localSearchSolverPhaseScope.getStartingScore());
             completedLocalSearchStepScope.setStepIndex(-1);
             completedLocalSearchStepScope.setTimeGradient(0.0);
         }
         localSearchSolverPhaseScope.setLastCompletedLocalSearchStepScope(completedLocalSearchStepScope);
         LocalSearchStepScope localSearchStepScope = new LocalSearchStepScope(localSearchSolverPhaseScope);
         localSearchStepScope.setStepIndex(completedLocalSearchStepScope.getStepIndex() + 1);
         localSearchStepScope.setSolutionInitialized(true);
         return localSearchStepScope;
     }
 
     public void phaseStarted(LocalSearchSolverPhaseScope localSearchSolverPhaseScope) {
         super.phaseStarted(localSearchSolverPhaseScope);
         .phaseStarted(localSearchSolverPhaseScope);
     }
 
     public void beforeDeciding(LocalSearchStepScope localSearchStepScope) {
         super.beforeDeciding(localSearchStepScope);
         .beforeDeciding(localSearchStepScope);
    }
    public void stepDecided(LocalSearchStepScope localSearchStepScope) {
        super.stepDecided(localSearchStepScope);
        .stepDecided(localSearchStepScope);
    }
    public void stepTaken(LocalSearchStepScope localSearchStepScope) {
        super.stepTaken(localSearchStepScope);
        .stepTaken(localSearchStepScope);
        LocalSearchSolverPhaseScope localSearchSolverPhaseScope = localSearchStepScope.getLocalSearchSolverPhaseScope();
        .debug("    Step index ({}), time spend ({}), score ({}), {} best score ({}), accepted move size ({})" +
                " for picked step ({}).",
                new Object[]{localSearchStepScope.getStepIndex(),
                        localSearchSolverPhaseScope.calculateSolverTimeMillisSpend(),
                        localSearchStepScope.getScore(),
                        (localSearchStepScope.getBestScoreImproved() ? "new" : "   "),
                        localSearchSolverPhaseScope.getBestScore(),
                        .getForager().getAcceptedMovesSize(),
                        localSearchStepScope.getStepString()});
    }
    public void phaseEnded(LocalSearchSolverPhaseScope localSearchSolverPhaseScope) {
        super.phaseEnded(localSearchSolverPhaseScope);
        .phaseEnded(localSearchSolverPhaseScope);
        .info("Phase local search finished: step total ({}), time spend ({}), best score ({}).",
                new Object[]{localSearchSolverPhaseScope.getLastCompletedStepScope().getStepIndex() + 1,
                localSearchSolverPhaseScope.calculateSolverTimeMillisSpend(),
                localSearchSolverPhaseScope.getBestScore()});
    }
New to GrepCode? Check out our FAQ X