【问题标题】:OptaPlanner - A planning entity is an instance of an entitySubclass (class java.lang.Integer) that is not configured as a planning entity.OptaPlanner - 计划实体是未配置为计划实体的 entitySubclass(java.lang.Integer 类)的实例。
【发布时间】:2016-04-06 14:31:44
【问题描述】:

我一直在尝试在 Optaplanner 中实现一个自定义 Construction Heuristic,以解决类似于护士排班问题的问题。

似乎所有内容都已正确注释,并已添加到SolverConfiguration,但我不断收到此错误:

Exception in thread "main" java.lang.IllegalArgumentException: A planning entity is an instance of an entitySubclass (class java.lang.Integer) that is not configured as a planning entity.
If that class (Integer) (or superclass thereof) is not a entityClass ([class org.optaplanner.examples.nurserostering.domain.SkillRequirement, class org.optaplanner.examples.nurserostering.domain.ShiftAssignment]), check your Solution implementation's annotated methods.
If it is, check your solver configuration.
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.findEntityDescriptorOrFail(SolutionDescriptor.java:398)
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.findVariableDescriptorOrFail(SolutionDescriptor.java:443)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.beforeVariableChanged(AbstractScoreDirector.java:226)
at org.optaplanner.examples.nurserostering.domain.solver.CustomConstructionHeuristic.changeWorkingSolution   (CustomConstructionHeuristic.java:86)
at org.optaplanner.core.impl.phase.custom.DefaultCustomPhase.doStep(DefaultCustomPhase.java:89)
at org.optaplanner.core.impl.phase.custom.DefaultCustomPhase.solve(DefaultCustomPhase.java:71)
at org.optaplanner.core.impl.solver.DefaultSolver.runPhases(DefaultSolver.java:214)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:176)
at org.optaplanner.examples.nurserostering.app.NurseRosterConsoleApp.main(NurseRosterConsoleApp.java:142)

我尝试使用这些参考来修复它:

OptaPlanner Xml configuration and entitySubclass is not configured as a planning entity error

OptaPlanner: java.lang.IllegalArgumentException

https://groups.google.com/forum/#!topic/optaplanner-dev/wCdeSQhGdaQ

到目前为止,没有任何效果。关于我如何解决这个问题的任何线索?

【问题讨论】:

  • 关于您的课程org.optaplanner.examples.nurserostering.domain.solver.CustomConstructionHeuristic - 请不要将包 org.optaplanner 用于您自己的项目(尤其是如果您打算将其部署到 Maven 存储库),因为它令人困惑(我认为这是我们的一个)。只需将整个护理示例(您复制的)的名称空间重构为例如com.xy.nurserostering

标签: optaplanner


【解决方案1】:

是的,该错误消息还不是 100% 用户友好,我会在 7.0 中修复它。

无论如何,它的意思是你的解决方案类中有这样的东西:

 @PlanningEntityCollectionProperty
 public List<Object> getMyEntities() {
     List<Object> entities = new ArrayList<>();
     entities.add(Integer.valueOf(1));
     ...
     return entities;
 }

因此,您将一个整数添加到应该只存在于实体之外的集合中(因此只存在于 SkillRequirement 或 ShiftAssignment 的实例之外)。

PS:SkillRequirement 是一个计划实体,这很奇怪,您可能希望在您的护士排班变体中给该类起一个更好的名称。

【讨论】:

  • 原来我将列表声明为 int 而不是 Integer,getter 和 setter 也是如此。我将它们都更正为Integer's,现在问题消失了。
  • 奇怪,因为 Integer 也不能是计划实体(Integer 类不是可变的并且没有 @PlanningEntity 注释,尽管 xml 注释稍后会允许最后一个问题)。
猜你喜欢
  • 1970-01-01
  • 2017-04-27
  • 1970-01-01
  • 1970-01-01
  • 2022-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多