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.config.constructionheuristic;
 
 import java.util.List;
 import java.util.Set;
 
 
 @XStreamAlias("constructionHeuristic")
 
     // Warning: all fields are null (and not defaulted) because they can be inherited
     // and also because the input config file should match the output config file
 
 
         return ;
     }
 
     public void setConstructionHeuristicType(ConstructionHeuristicType constructionHeuristicType) {
         this. = constructionHeuristicType;
     }
 
         return ;
     }
 
     public void setConstructionHeuristicPickEarlyType(ConstructionHeuristicPickEarlyType constructionHeuristicPickEarlyType) {
         this. = constructionHeuristicPickEarlyType;
     }
 
     // ************************************************************************
     // Builder methods
     // ************************************************************************
 
     // TODO rename GreedyFitSolverPhase to ConstructionHeuristicSolverPhase
     public GreedyFitSolverPhase buildSolverPhase(EnvironmentMode environmentModeSolutionDescriptor solutionDescriptor,
             ScoreDefinition scoreDefinitionTermination solverTermination) {
         if ( != null) {
             DefaultGreedyFitSolverPhase greedySolverPhase = new DefaultGreedyFitSolverPhase();
             configureSolverPhase(greedySolverPhaseenvironmentModescoreDefinitionsolverTermination);
             greedySolverPhase.setGreedyPlanningEntitySelector(buildGreedyPlanningEntitySelector(solutionDescriptor));
             greedySolverPhase.setGreedyDecider(buildGreedyDecider(solutionDescriptorenvironmentMode));
             if (environmentMode == . || environmentMode == .) {
                 greedySolverPhase.setAssertStepScoreIsUncorrupted(true);
             }
             return greedySolverPhase;
         } else if (false) {
             if ( != null) {
                 // TODO throw exception
             }
             // TODO support detailed configuration
             throw new UnsupportedOperationException("Detailed configuration is not yet implemented.");
         } else {
             throw new IllegalArgumentException("A constructionHeuristic requires configuration, " +
                     "for example a constructionHeuristicType.");
         }
     }
 
         GreedyPlanningEntitySelector greedyPlanningEntitySelector = new GreedyPlanningEntitySelector();
 
        Set<Class<?>> planningEntityImplementationClassSet = solutionDescriptor.getPlanningEntityImplementationClassSet();
        if (planningEntityImplementationClassSet.size() != 1) {
            // TODO Multiple MUST BE SUPPORTED TOO
            throw new UnsupportedOperationException("Currently the greedyFit implementation only supports " +
                    "1 planningEntityImplementationClass.");
        }
        Class<?> planningEntityImplementationClass = planningEntityImplementationClassSet.iterator().next();
        List<PlanningEntitySelectorplanningEntitySelectorList = new ArrayList<PlanningEntitySelector>(1);
        PlanningEntitySelector planningEntitySelector = new PlanningEntitySelector(
                solutionDescriptor.getPlanningEntityDescriptor(planningEntityImplementationClass));
        planningEntitySelector.setSelectionOrder(determinePlanningEntitySelectionOrder());
        planningEntitySelector.setResetInitializedPlanningEntities(false);
        planningEntitySelectorList.add(planningEntitySelector);
        greedyPlanningEntitySelector.setPlanningEntitySelectorList(planningEntitySelectorList);
        return greedyPlanningEntitySelector;
    }
    private GreedyDecider buildGreedyDecider(SolutionDescriptor solutionDescriptorEnvironmentMode environmentMode) {
        DefaultGreedyDecider greedyDecider = new DefaultGreedyDecider();
        ConstructionHeuristicPickEarlyType pickEarlyType = (this. == null)
        Set<Class<?>> planningEntityImplementationClassSet = solutionDescriptor.getPlanningEntityImplementationClassSet();
        if (planningEntityImplementationClassSet.size() != 1) {
            // TODO Multiple MUST BE SUPPORTED TOO
            throw new UnsupportedOperationException("Currently the greedyFit implementation only supports " +
                    "1 planningEntityImplementationClass.");
        }
        Class<?> planningEntityImplementationClass = planningEntityImplementationClassSet.iterator().next();
        PlanningEntityDescriptor planningEntityDescriptor = solutionDescriptor.getPlanningEntityDescriptor(planningEntityImplementationClass);
        PlanningVariableWalker planningVariableWalker = new PlanningVariableWalker(planningEntityDescriptor);
        List<PlanningValueWalkerplanningValueWalkerList = new ArrayList<PlanningValueWalker>();
        for (PlanningVariableDescriptor planningVariableDescriptor
                : planningEntityDescriptor.getPlanningVariableDescriptors()) {
            PlanningValueSelector planningValueSelector = new PlanningValueSelector(planningVariableDescriptor);
            planningValueSelector.setSelectionOrder(determinePlanningValueSelectionOrder());
            PlanningValueWalker planningValueWalker = new PlanningValueWalker(
                    planningVariableDescriptorplanningValueSelector);
            planningValueWalkerList.add(planningValueWalker);
        }
        planningVariableWalker.setPlanningValueWalkerList(planningValueWalkerList);
        greedyDecider.setPlanningVariableWalker(planningVariableWalker);
        
        greedyDecider.setConstructionHeuristicPickEarlyType(pickEarlyType);
        if (environmentMode == .) {
            greedyDecider.setAssertMoveScoreIsUncorrupted(true);
        }
        return greedyDecider;
    }
        switch () {
            case :
            case :
                return .;
            case :
            case :
                return .;
            default:
                throw new IllegalStateException("The constructionHeuristicType ("
                        +  + ") is not implemented");
        }
    }
        switch () {
            case :
            case :
                return .;
            case :
            case :
                return .;
            default:
                throw new IllegalStateException("The constructionHeuristicType ("
                        +  + ") is not implemented");
        }
    }
    public void inherit(ConstructionHeuristicSolverPhaseConfig inheritedConfig) {
        super.inherit(inheritedConfig);
        if ( == null) {
             = inheritedConfig.getConstructionHeuristicType();
        }
        if ( == null) {
        }
    }
    public static enum ConstructionHeuristicType {
        FIRST_FIT,
        FIRST_FIT_DECREASING,
        BEST_FIT,
        BEST_FIT_DECREASING
    }
New to GrepCode? Check out our FAQ X