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.phase.custom;
Default implementation of CustomSolverPhase.
        implements CustomSolverPhase {
    public void setCustomSolverPhaseCommandList(List<CustomSolverPhaseCommandcustomSolverPhaseCommandList) {
        this. = customSolverPhaseCommandList;
    }
    // ************************************************************************
    // Worker methods
    // ************************************************************************
    public void solve(DefaultSolverScope solverScope) {
        CustomSolverPhaseScope customSolverPhaseScope = new CustomSolverPhaseScope(solverScope);
        phaseStarted(customSolverPhaseScope);
        CustomStepScope customStepScope = createNextStepScope(customSolverPhaseScopenull);
        while (!.isPhaseTerminated(customSolverPhaseScope) && commandIterator.hasNext()) {
            CustomSolverPhaseCommand customSolverPhaseCommand = commandIterator.next();
            customSolverPhaseCommand.changeWorkingSolution(solverScope.getSolutionDirector());
            Score score = customSolverPhaseScope.calculateScoreFromWorkingMemory();
            customStepScope.setScore(score);
            stepTaken(customStepScope);
            customStepScope = createNextStepScope(customSolverPhaseScopecustomStepScope);
        }
        phaseEnded(customSolverPhaseScope);
    }
    private CustomStepScope createNextStepScope(CustomSolverPhaseScope customSolverPhaseScopeCustomStepScope completedCustomStepScope) {
        if (completedCustomStepScope == null) {
            completedCustomStepScope = new CustomStepScope(customSolverPhaseScope);
            completedCustomStepScope.setScore(customSolverPhaseScope.getStartingScore());
            completedCustomStepScope.setStepIndex(-1);
        }
        customSolverPhaseScope.setLastCompletedCustomStepScope(completedCustomStepScope);
        CustomStepScope customStepScope = new CustomStepScope(customSolverPhaseScope);
        customStepScope.setStepIndex(completedCustomStepScope.getStepIndex() + 1);
        customStepScope.setSolutionInitialized(true);
        return customStepScope;
    }
    public void phaseStarted(CustomSolverPhaseScope customSolverPhaseScope) {
        super.phaseStarted(customSolverPhaseScope);
    }
    public void stepTaken(CustomStepScope customStepScope) {
        super.stepTaken(customStepScope);
        CustomSolverPhaseScope customSolverPhaseScope = customStepScope.getCustomSolverPhaseScope();
        .debug("Step index ({}), time spend ({}), score ({}), {} best score ({}).",
                new Object[]{customStepScope.getStepIndex(),
                        customSolverPhaseScope.calculateSolverTimeMillisSpend(),
                        customStepScope.getScore(), (customStepScope.getBestScoreImproved() ? "new" : "   "),
                        customSolverPhaseScope.getBestScore()});
    }
    public void phaseEnded(CustomSolverPhaseScope customSolverPhaseScope) {
        super.phaseEnded(customSolverPhaseScope);
        .info("Custom phase ended at step index ({}) for best score ({}).",
                customSolverPhaseScope.getLastCompletedStepScope().getStepIndex(),
                customSolverPhaseScope.getBestScore());
    }
New to GrepCode? Check out our FAQ X