构造问题 - selectorConfig(EntitySelectorConfig(null))没有entityClass

时间:2015-04-10 15:57:34

标签: optaplanner

我宣布了两个有自己的计划变量的计划实体Run和School。在求解器配置中,每个实体都有单独的构造启发式,但是有一个问题,即selectorConfig没有实体类。使用OptaPlanner 6.2.0。非常感谢任何帮助。

<constructionHeuristic>
    <queuedEntityPlacer>
        <entitySelector id="placerEntitySelector">
            <entityClass>org.optaplanner.examples.cloudbalancing.domain.Run</entityClass>
            <cacheType>PHASE</cacheType>
        </entitySelector>
        <changeMoveSelector>
            <entitySelector mimicSelectorRef="placerEntitySelector"/>
        </changeMoveSelector>
    </queuedEntityPlacer>
</constructionHeuristic>

<constructionHeuristic>
    <queuedEntityPlacer>
        <entitySelector id="placerEntitySelector">
            <entityClass>org.optaplanner.examples.cloudbalancing.domain.School</entityClass>
            <cacheType>PHASE</cacheType>
        </entitySelector>
        <changeMoveSelector>
            <entitySelector mimicSelectorRef="placerEntitySelector"/>
        </changeMoveSelector>
    </queuedEntityPlacer>
</constructionHeuristic>

堆栈跟踪

&#13;
&#13;
--- exec-maven-plugin:1.2.1:exec (default-cli) @ optaplanner-examples ---
Exception in thread "main" java.lang.IllegalArgumentException: The selectorConfig (EntitySelectorConfig(null)) has no entityClass (null) configured and because there are multiple in the entityClassSet ([class org.optaplanner.examples.cloudbalancing.domain.Run, class org.optaplanner.examples.cloudbalancing.domain.School]), it can not be deducted automatically.
	at org.optaplanner.core.config.heuristic.selector.SelectorConfig.deduceEntityDescriptor(SelectorConfig.java:81)
	at org.optaplanner.core.config.heuristic.selector.entity.EntitySelectorConfig.buildEntitySelector(EntitySelectorConfig.java:210)
	at org.optaplanner.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig.buildBaseMoveSelector(ChangeMoveSelectorConfig.java:64)
	at org.optaplanner.core.config.heuristic.selector.move.MoveSelectorConfig.buildMoveSelector(MoveSelectorConfig.java:189)
	at org.optaplanner.core.config.heuristic.selector.move.composite.UnionMoveSelectorConfig.buildBaseMoveSelector(UnionMoveSelectorConfig.java:75)
	at org.optaplanner.core.config.heuristic.selector.move.MoveSelectorConfig.buildMoveSelector(MoveSelectorConfig.java:189)
	at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildMoveSelector(LocalSearchPhaseConfig.java:143)
	at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildDecider(LocalSearchPhaseConfig.java:108)
	at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildPhase(LocalSearchPhaseConfig.java:93)
	at org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig.buildPhase(LocalSearchPhaseConfig.java:46)
	at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:205)
	at org.optaplanner.core.impl.solver.XStreamXmlSolverFactory.buildSolver(XStreamXmlSolverFactory.java:134)
	at org.optaplanner.examples.cloudbalancing.app.CloudBalancingHelloWorld.main(CloudBalancingHelloWorld.java:38)
------------------------------------------------------------------------
BUILD FAILURE
&#13;
&#13;
&#13;

这里是移动选择器的定义。工作就像一个魅力。我采取了不同的方法,看看它是否比我原来的更好。我确实知道选择最好的实体和变量并不总是很明显。我从原始解决方案中获取了一个粒度变量,并将其替换为粗实体和变量,无法对任何目标进行渐进式计分。结果是增量评分规则阻止课程实体和变量改变状态 - 并且编写细粒度评分规则是不可能的。因此,在定义实体和变量时,它们应该能够支持粒度/增量评分。我原来的方法产生了预期的结果。

    <localSearch>
    <unionMoveSelector>
        <changeMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.cloudbalancing.domain.Run</entityClass>
            </entitySelector>
            <valueSelector>
                <variableName>vehicle</variableName>
            </valueSelector>
        </changeMoveSelector>
        <swapMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.cloudbalancing.domain.Run</entityClass>
            </entitySelector>
        </swapMoveSelector>
        <changeMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.cloudbalancing.domain.School</entityClass>
            </entitySelector>
            <valueSelector>
                <variableName>startTime</variableName>
            </valueSelector>
        </changeMoveSelector>
        <swapMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.cloudbalancing.domain.School</entityClass>
            </entitySelector>
        </swapMoveSelector>
    </unionMoveSelector>

...

1 个答案:

答案 0 :(得分:1)

异常发生在LocalSearchPhaseConfig.build...(),而不是ConstructionHeuristicPhaseCondif.build...(),因此这是<localSearch>配置的问题,此处未粘贴。

我怀疑你没有在那里配置moveSelectors而只是依赖于开箱即用的那些,如果有多个实体类或变量(I made a jira for that),那么它们不能正常工作。