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.heuristic.selector.variable;
 
 import java.util.List;
 
Determines the order in which the planning values of 1 planning entity class are selected for an algorithm
 
 
 
     private boolean roundRobinSelection = false// TODO
 
     private Random workingRandom;
     private Collection<?> cachedPlanningValues = null;
 
     public PlanningValueSelector(PlanningVariableDescriptor planningVariableDescriptor) {
         this. = planningVariableDescriptor;
     }
 
     public void setSelectionOrder(PlanningValueSelectionOrder selectionOrder) {
         this. = selectionOrder;
     }
 
     public void setSelectionPromotion(PlanningValueSelectionPromotion selectionPromotion) {
         this. = selectionPromotion;
     }
 
     public void setRoundRobinSelection(boolean roundRobinSelection) {
         this. = roundRobinSelection;
     }
 
     // ************************************************************************
     // Worker methods
     // ************************************************************************
 
     @Override
     public void phaseStarted(AbstractSolverPhaseScope solverPhaseScope) {
         validateConfiguration();
          = solverPhaseScope.getSolutionDirector();
          = solverPhaseScope.getWorkingRandom();
         initSelectedPlanningValueList(solverPhaseScope);
     }
 
     private void validateConfiguration() {
             PlanningValueSorter valueSorter = .getValueSorter();
             if (!valueSorter.isSortStrengthSupported()) {
                 throw new IllegalStateException("The selectionOrder (" + 
                         + ") can not be used on PlanningEntity ("
                         + .getPlanningEntityDescriptor().getPlanningEntityClass().getName()
                         + ")'s planningVariable (" + .getVariablePropertyName()
                         + ") that has no support for strength sorting. Check the @PlanningVariable annotation.");
             }
         }
     }
 
     private void initSelectedPlanningValueList(AbstractSolverPhaseScope solverPhaseScope) {
             Collection<?> planningValues = .extractPlanningValues(
                     solverPhaseScope.getSolutionDirector(), null);
              = applySelectionOrder(planningValues);
         } else {
              = null;
         }
     }
 
     @Override
     public void phaseEnded(AbstractSolverPhaseScope solverPhaseScope) {
         = null;
    }
    public Iterator<?> iterator(Object planningEntity) {
        if ( != null) {
            return .iterator();
        } else {
            Collection<?> planningValues = .extractPlanningValues(
                    planningEntity);
            planningValues = applySelectionOrder(planningValues);
            return planningValues.iterator();
        }
    }
    private Collection<?> applySelectionOrder(Collection<?> workingPlanningValues) {
        switch () {
            case :
                return workingPlanningValues;
            case :
                List<ObjectrandomPlanningValueList = new ArrayList<Object>(workingPlanningValues);
                Collections.shuffle(randomPlanningValueList);
                return randomPlanningValueList;
            case :
                List<ObjectincreasingStrengthPlanningValueList = new ArrayList<Object>(workingPlanningValues);
                PlanningValueSorter valueSorter = .getValueSorter();
                valueSorter.sortStrengthAscending(
                        .getWorkingSolution(), increasingStrengthPlanningValueList);
                return increasingStrengthPlanningValueList;
            default:
                throw new IllegalStateException("The selectionOrder (" +  + ") is not implemented");
        }
    }
New to GrepCode? Check out our FAQ X