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.constructionheuristic.greedyFit;
 
 
Default implementation of GreedyFitSolverPhase.
 
 
     protected GreedyDecider greedyDecider;
 
     protected boolean assertStepScoreIsUncorrupted = false;
     
     public void setGreedyPlanningEntitySelector(GreedyPlanningEntitySelector greedyPlanningEntitySelector) {
         this. = greedyPlanningEntitySelector;
     }
 
     public void setGreedyDecider(GreedyDecider greedyDecider) {
         this. = greedyDecider;
     }
 
     public void setAssertStepScoreIsUncorrupted(boolean assertStepScoreIsUncorrupted) {
         this. = assertStepScoreIsUncorrupted;
     }
 
     // ************************************************************************
     // Worker methods
     // ************************************************************************
 
     public void solve(DefaultSolverScope solverScope) {
         GreedyFitSolverPhaseScope greedyFitSolverPhaseScope = new GreedyFitSolverPhaseScope(solverScope);
         phaseStarted(greedyFitSolverPhaseScope);
 
         GreedyFitStepScope greedyFitStepScope = createNextStepScope(greedyFitSolverPhaseScopenull);
         Iterator it = .iterator();
         while (!.isPhaseTerminated(greedyFitSolverPhaseScope) && it.hasNext()) {
             Object planningEntity = it.next();
             greedyFitStepScope.setPlanningEntity(planningEntity);
             beforeDeciding(greedyFitStepScope);
             .decideNextStep(greedyFitStepScope);
             stepDecided(greedyFitStepScope);
             greedyFitStepScope.doStep();
             if (!it.hasNext()) {
                 greedyFitStepScope.setSolutionInitialized(true);
             }
             if () {
                 greedyFitSolverPhaseScope.assertWorkingScore(greedyFitStepScope.getScore());
             }
             stepTaken(greedyFitStepScope);
             greedyFitStepScope = createNextStepScope(greedyFitSolverPhaseScopegreedyFitStepScope);
         }
         phaseEnded(greedyFitSolverPhaseScope);
     }
 
     private GreedyFitStepScope createNextStepScope(GreedyFitSolverPhaseScope greedyFitSolverPhaseScopeGreedyFitStepScope completedGreedyFitStepScope) {
         if (completedGreedyFitStepScope == null) {
             completedGreedyFitStepScope = new GreedyFitStepScope(greedyFitSolverPhaseScope);
             completedGreedyFitStepScope.setScore(greedyFitSolverPhaseScope.getStartingScore());
             completedGreedyFitStepScope.setStepIndex(-1);
         }
         greedyFitSolverPhaseScope.setLastCompletedGreedyFitStepScope(completedGreedyFitStepScope);
         GreedyFitStepScope greedyFitStepScope = new GreedyFitStepScope(greedyFitSolverPhaseScope);
         greedyFitStepScope.setStepIndex(completedGreedyFitStepScope.getStepIndex() + 1);
         greedyFitStepScope.setSolutionInitialized(false);
         return greedyFitStepScope;
     }
 
     public void phaseStarted(GreedyFitSolverPhaseScope greedyFitSolverPhaseScope) {
         super.phaseStarted(greedyFitSolverPhaseScope);
         .phaseStarted(greedyFitSolverPhaseScope);
         .phaseStarted(greedyFitSolverPhaseScope);
     }
 
     public void beforeDeciding(GreedyFitStepScope greedyFitStepScope) {
         super.beforeDeciding(greedyFitStepScope);
         .beforeDeciding(greedyFitStepScope);
         .beforeDeciding(greedyFitStepScope);
    }
    public void stepDecided(GreedyFitStepScope greedyFitStepScope) {
        super.stepDecided(greedyFitStepScope);
        .stepDecided(greedyFitStepScope);
        .stepDecided(greedyFitStepScope);
    }
    public void stepTaken(GreedyFitStepScope greedyFitStepScope) {
        super.stepTaken(greedyFitStepScope);
        .stepTaken(greedyFitStepScope);
        .stepTaken(greedyFitStepScope);
        .debug("    Step index ({}), time spend ({}), score ({}), initialized planning entity ({}).",
                new Object[]{greedyFitStepScope.getStepIndex(),
                        greedyFitStepScope.getGreedyFitSolverPhaseScope().calculateSolverTimeMillisSpend(),
                        greedyFitStepScope.getScore(),
                        greedyFitStepScope.getPlanningEntity()});
    }
    public void phaseEnded(GreedyFitSolverPhaseScope greedyFitSolverPhaseScope) {
        super.phaseEnded(greedyFitSolverPhaseScope);
        .phaseEnded(greedyFitSolverPhaseScope);
        .phaseEnded(greedyFitSolverPhaseScope);
        .info("Phase construction heuristic finished: step total ({}), time spend ({}), best score ({}).",
                new Object[]{greedyFitSolverPhaseScope.getLastCompletedStepScope().getStepIndex() + 1,
                greedyFitSolverPhaseScope.calculateSolverTimeMillisSpend(),
                greedyFitSolverPhaseScope.getBestScore()});
    }
New to GrepCode? Check out our FAQ X