OptaPlanner Xml配置和entitySubclass未配置为规划实体错误



我是OptaPlanner的新手,在配置解决方案时遇到了一些困难。我已经正确地注释了所有的类,但是当求解器运行时,我得到了以下错误。

A planning entity is an instance of a entitySubclass (class 
org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector) that is not 
configured as a planning entity.
If that class (DroolsScoreDirector) (or superclass thereof) is not a entityClass 
([...Part]), check your Solution implementation's annotated methods.
If it is, check your solver configuration

这是我目前使用的xml配置。

<?xml version="1.0" encoding="UTF-8"?>
<solver>
    <solutionClass>(package name).SheetNesting</solutionClass>
    <planningEntityClass>(package name).Part</planningEntityClass>
    <scoreDirectorFactory>
        <scoreDefinitionType>HARD_SOFT</scoreDefinitionType>
        <scoreDrl>/Resources/Drools/NestingRules.drl</scoreDrl>
    </scoreDirectorFactory>
    <termination>
        <maximumSecondsSpend>500</maximumSecondsSpend>
    </termination>
    <constructionHeuristic>
        <constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>
    </constructionHeuristic>
    <localSearch>
    <unionMoveSelector>
      <changeMoveSelector>
        <valueSelector>
          <variableName>sheet</variableName>
        </valueSelector>
      </changeMoveSelector>
      <moveListFactory>
          <moveListFactoryClass>(package name).XPosMoveFactory</moveListFactoryClass>
      </moveListFactory>
      <moveListFactory>
          <moveListFactoryClass>(package name).YPosMoveFactory</moveListFactoryClass>
      </moveListFactory>
    </unionMoveSelector>
    <acceptor>
      <lateAcceptanceSize>600</lateAcceptanceSize>
    </acceptor>
    <forager>
      <acceptedCountLimit>4</acceptedCountLimit>
    </forager>
  </localSearch>
</solver>

输出显示解决方案建立(可能评估Phase(0)),但随后抛出错误。如有任何帮助,不胜感激。

*编辑首先感谢您的评论。Part类的定义如下

@PlanningEntity(difficultyComparatorClass = PartComparator.class)
public class Part 
{
     ....
    @PlanningVariable(valueRangeProviderRefs = {"sheetRange"})
    public Sheet getSheet()
    {
        ....
    }

    @PlanningVariable(valueRangeProviderRefs = {"xPosRange"})
    public double getXCenter()
    {
        ....
    }
    @PlanningVariable(valueRangeProviderRefs = {"yPosRange"})
    public double getYCenter()
    {
        ....
    }
}

可以看到,如前所述,类被完全注释了。这就是为什么我认为问题出在配置上。

似乎错误告诉你,你的(包名)。Part类没有像文档中描述的那样用@PlanningEntity和@PlanningVariable注释:http://docs.jboss.org/drools/release/6.0.1.Final/optaplanner-docs/html_single/index.html planningEntity

如果你的类注释正确,请在你的问题中与我们分享

这个问题的错误消息有点误导人。然而,它是准确的。这个问题是由配置的一个组件引起的,完全是我的疏忽。

自定义move方法通过beforeVariableChanged(object, string)方法而不是Part类来传递score director。

谢谢你的帮助。

最新更新