Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.drools.planner.core.heuristic.selector.entity;
  
  import java.util.Iterator;
  import java.util.List;
  
Determines the order in which the planning entities of 1 planning entity class are selected for an algorithm
 
         implements Iterable<Object> {
 
 
     private boolean resetInitializedPlanningEntities = false;
 
     private List<ObjectselectedPlanningEntityList = null;
 
     public PlanningEntitySelector(PlanningEntityDescriptor planningEntityDescriptor) {
         this. = planningEntityDescriptor;
     }
 
     public void setSelectionOrder(PlanningEntitySelectionOrder selectionOrder) {
         this. = selectionOrder;
     }
 
     public void setResetInitializedPlanningEntities(boolean resetInitializedPlanningEntities) {
         this. = resetInitializedPlanningEntities;
     }
 
     // ************************************************************************
     // Worker methods
     // ************************************************************************
 
     @Override
     public void phaseStarted(AbstractSolverPhaseScope solverPhaseScope) {
         validateConfiguration();
         initSelectedPlanningEntityList(solverPhaseScope);
     }
 
     private void validateConfiguration() {
             PlanningEntitySorter planningEntitySorter = .getPlanningEntitySorter();
             if (!planningEntitySorter.isSortDifficultySupported()) {
                 throw new IllegalStateException("The selectionOrder (" + 
                         + ") can not be used on a PlanningEntity ("
                         + .getPlanningEntityClass().getName()
                         + ") that has no support for difficulty sorting. Check the @PlanningEntity annotation.");
             }
         }
     }
 
     private void initSelectedPlanningEntityList(AbstractSolverPhaseScope solverPhaseScope) {
         List<ObjectworkingPlanningEntityList = solverPhaseScope.getWorkingPlanningEntityList();
         for (Iterator<Objectit = workingPlanningEntityList.iterator(); it.hasNext(); ) {
             Object planningEntity = it.next();
             if (!.getPlanningEntityClass().isInstance(planningEntity)) {
                 it.remove();
             } else if (.isInitialized(planningEntity)) {
                 if () {
                     WorkingMemory workingMemory = solverPhaseScope.getWorkingMemory();
                     workingMemory.retract(workingMemory.getFactHandle(planningEntity));
                     .uninitialize(planningEntity);
                 } else {
                     // Do not plan the initialized planning entity
                     it.remove();
                 }
             }
         }
         switch () {
             case :
                 break;
             case :
                 Collections.shuffle(workingPlanningEntityListsolverPhaseScope.getWorkingRandom());
                 break;
             case :
                 PlanningEntitySorter planningEntitySorter = .getPlanningEntitySorter();
                 planningEntitySorter.sortDifficultyDescending(
                         solverPhaseScope.getWorkingSolution(), workingPlanningEntityList);
                 break;
             default:
                 throw new IllegalStateException("The selectionOrder (" +  + ") is not implemented");
         }
          = workingPlanningEntityList;
     }
 
     @Override
     public void phaseEnded(AbstractSolverPhaseScope solverPhaseScope) {
          = null;
     }
 
     public Iterator<Objectiterator() {
        return .iterator();
    }
New to GrepCode? Check out our FAQ X