Package org.drools.planner.config.constructionheuristic.greedyFit

Source Code of org.drools.planner.config.constructionheuristic.greedyFit.GreedyFitPlanningEntityConfig

/*
* 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.greedyFit;

import java.util.Set;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.drools.planner.core.domain.entity.PlanningEntityDescriptor;
import org.drools.planner.core.domain.solution.SolutionDescriptor;
import org.drools.planner.core.heuristic.selector.entity.PlanningEntitySelectionOrder;
import org.drools.planner.core.heuristic.selector.entity.PlanningEntitySelector;

@XStreamAlias("greedyFitPlanningEntity")
@Deprecated // Use ConstructionHeuristicSolverPhaseConfig
public class GreedyFitPlanningEntityConfig {

    // 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

    protected Class<?> planningEntityClass = null;

    protected PlanningEntitySelectionOrder selectionOrder = null;
    protected Boolean resetInitializedPlanningEntities = null;

    public PlanningEntitySelectionOrder getSelectionOrder() {
        return selectionOrder;
    }

    public void setSelectionOrder(PlanningEntitySelectionOrder selectionOrder) {
        this.selectionOrder = selectionOrder;
    }

    public Boolean getResetInitializedPlanningEntities() {
        return resetInitializedPlanningEntities;
    }

    public void setResetInitializedPlanningEntities(Boolean resetInitializedPlanningEntities) {
        this.resetInitializedPlanningEntities = resetInitializedPlanningEntities;
    }

    // ************************************************************************
    // Builder methods
    // ************************************************************************

    public PlanningEntitySelector buildPlanningEntitySelector(SolutionDescriptor solutionDescriptor) {
        PlanningEntityDescriptor planningEntityDescriptor;
        Class<?> resolvedEntityClass;
        if (planningEntityClass != null) {
            resolvedEntityClass = planningEntityClass;
        } else {
            Set<Class<?>> planningEntityClassSet
                    = solutionDescriptor.getPlanningEntityClassSet();
            if (planningEntityClassSet.size() != 1) {
                throw new IllegalArgumentException(
                        "The greedyFitPlanningEntity has no planningEntityClass but there are multiple ("
                                + planningEntityClassSet.size() + ") planningEntityClasses.");
            }
            resolvedEntityClass = planningEntityClassSet.iterator().next();
        }
        if (!solutionDescriptor.hasPlanningEntityDescriptor(planningEntityClass)) {
            throw new IllegalArgumentException("The greedyFitPlanningEntity has a planningEntityClass ("
                    + planningEntityClass + ") that has not been configured as a planningEntity.");
        }
        planningEntityDescriptor = solutionDescriptor.getPlanningEntityDescriptor(planningEntityClass);
        PlanningEntitySelector planningEntitySelector = new PlanningEntitySelector(planningEntityDescriptor);
        planningEntitySelector.setSelectionOrder(selectionOrder != null ? selectionOrder
                : PlanningEntitySelectionOrder.ORIGINAL);
        planningEntitySelector.setResetInitializedPlanningEntities(resetInitializedPlanningEntities != null ?
                resetInitializedPlanningEntities.booleanValue() : false);
        return planningEntitySelector;
    }

    public void inherit(GreedyFitPlanningEntityConfig inheritedConfig) {
        if (selectionOrder == null) {
            selectionOrder = inheritedConfig.getSelectionOrder();
        }
        if (resetInitializedPlanningEntities == null) {
            resetInitializedPlanningEntities = inheritedConfig.getResetInitializedPlanningEntities();
        }
    }

}
TOP

Related Classes of org.drools.planner.config.constructionheuristic.greedyFit.GreedyFitPlanningEntityConfig

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.