OptaPlanner 解决方案使用两个实体 类 和排队变量(列表变量)。错误 "there are multiple in the entityClassSet"

OptaPlanner solution using two entity classes with queued variables(list variables). Error "there are multiple in the entityClassSet"

我用的是OptaPlanner 8.19.0。问题有两个entityClass.

但是出现如下异常:

Failed to instantiate [org.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; nested exception is java.lang.IllegalArgumentException: The config (QueuedValuePlacerConfig(ValueSelectorConfig(taskCombos), ChangeMoveSelectorConfig(null, ValueSelectorConfig(null)))) has no entityClass configured and because there are multiple in the entityClassSet ([class com.aiseeding.aps.hf.domain.MachineStageFirst, class com.aiseeding.aps.hf.domain.MachineStageSecond]), it cannot be deduced automatically.

PlanningEntity1和PlanningEntity2相同,只是取值范围不同。 我尝试在@PlanngingEntity 上使用 valueRangeProvider,但 optaplanner 说列表变量不支持它。所以我使用了两个实体 class 并且每个实体 class 都有一个 valueProviderRange

解决方案Class:

@PlanningSolution
@XStreamAlias("TaTaskAssigningSolution")
public class APSSolution extends AbstractPersistable {

    @ProblemFactCollectionProperty
    private List<Tank> taskTypeList;

    @ValueRangeProvider(id = "taskRangeStageFirst")
    @ProblemFactCollectionProperty
    private List<TaskCombo> taskComboListStageFirst;

    @ValueRangeProvider(id = "taskRangeStageSecond")
    @ProblemFactCollectionProperty
    private List<TaskCombo> taskComboListStageSecond;

    @ProblemFactCollectionProperty
    private List<Tank> tankList;

    @PlanningEntityCollectionProperty
    private List<Machine> machineList;

    @PlanningEntityCollectionProperty
    private List<Machine> machineListSecond;

    @XStreamConverter(BendableScoreXStreamConverter.class)
    @PlanningScore(bendableHardLevelsSize = 1, bendableSoftLevelsSize = 4)

    private BendableLongScore score;

    /** Relates to {@link Task#()}. */
    private int frozenCutoff; // In minutes

    private Param param;
    private List<Stage> stageList;
    private Map<String,Task> taskMap;
    private Map<String,Machine> machineMap;

    public APSSolution(long id){}
}

PlanningEntity1 和 PlanningEntity2:

@PlanningEntity
@XStreamAlias("TaEmployee")
public class MachineStageFirst extends Machine {

    @PlanningListVariable(valueRangeProviderRefs = "taskRangeStageFirst")
    private List<TaskCombo> taskCombos;

    public MachineStageFirst()
    {    }

    public MachineStageFirst(long id, String fullName) {
        super.setId(id);
        super.setFullName(fullName);
        setTaskCombos(new ArrayList<>());
    }

    public List<TaskCombo> getTaskCombos() {
        return taskCombos;
    }

    public void setTaskCombos(List<TaskCombo> taskCombos) {
        this.taskCombos = taskCombos;
    }
}

配置 XML:

<?xml version="1.0" encoding="UTF-8"?>
<solver>
  <!--<environmentMode>FULL_ASSERT</environmentMode>--><!-- To slowly prove there are no bugs in this code -->
  <moveThreadCount>1</moveThreadCount> To solve faster by saturating multiple CPU cores

  <solutionClass>com.aps.hf.domain.APSSolution</solutionClass>
  <entityClass>com.aps.hf.domain.MachineStageFirst</entityClass>
  <entityClass>com.aps.hf.domain.MachineStageSecond</entityClass>


  <scoreDirectorFactory>
    <easyScoreCalculatorClass>com.aiseeding.aps.hf.score.APSConstraintScoreCalculator</easyScoreCalculatorClass>
  </scoreDirectorFactory>

  <termination>
    <secondsSpentLimit>10</secondsSpentLimit>
  </termination>

  <constructionHeuristic>
    <queuedValuePlacer>
      <entitySelector>
        <entityClass>com.aiseeding.aps.hf.domain.MachineStageFirst</entityClass>
      </entitySelector>
      <valueSelector id="placerValueSelector">
        <cacheType>PHASE</cacheType>
        <selectionOrder>SORTED</selectionOrder>
        <sorterManner>INCREASING_STRENGTH</sorterManner>
      </valueSelector>
      <changeMoveSelector>
        <entitySelector>
          <cacheType>PHASE</cacheType>
          <selectionOrder>SORTED</selectionOrder>
          <sorterManner>DECREASING_DIFFICULTY</sorterManner>
        </entitySelector>
        <valueSelector mimicSelectorRef="placerValueSelector"/>
      </changeMoveSelector>
    </queuedValuePlacer>
  </constructionHeuristic>

  <constructionHeuristic>
    <queuedValuePlacer>
      <entitySelector>
        <entityClass>com.aiseeding.aps.hf.domain.MachineStageSecond</entityClass>
      </entitySelector>
      <valueSelector id="placerValueSelector">
        <cacheType>PHASE</cacheType>
        <selectionOrder>SORTED</selectionOrder>
        <sorterManner>INCREASING_STRENGTH</sorterManner>
      </valueSelector>
      <changeMoveSelector>
        <entitySelector>
          <cacheType>PHASE</cacheType>
          <selectionOrder>SORTED</selectionOrder>
          <sorterManner>DECREASING_DIFFICULTY</sorterManner>
        </entitySelector>
        <valueSelector mimicSelectorRef="placerValueSelector"/>
      </changeMoveSelector>
    </queuedValuePlacer>
  </constructionHeuristic>

  <localSearch>
    <changeMoveSelector>
      <entitySelector>
        ... <!-- Normal selector properties -->
        <entityClass>com.aps.hf.domain.MachineStageFirst</entityClass>
      </entitySelector>
      <selectionOrder>ORIGINAL</selectionOrder>
    </changeMoveSelector>

    <acceptor>
      <entityTabuSize>5</entityTabuSize>
    </acceptor>
    <forager>
    </forager>
  </localSearch>
  <localSearch>
    <changeMoveSelector>
      <entitySelector>
        ... <!-- Normal selector properties -->
        <entityClass>com.aps.hf.domain.MachineStageSecond</entityClass>
      </entitySelector>
      <selectionOrder>ORIGINAL</selectionOrder>
    </changeMoveSelector>

    <acceptor>
      <entityTabuSize>5</entityTabuSize>
    </acceptor>
    <forager>
    </forager>
  </localSearch>

</solver>

问题是由两个实体调用还是队列变量引起的?

非常感谢~

具有多个实体的案例 类(每个实体至少有一个真正的 (=non-shadow) 规划变量)是困难且罕见的。

@PlanningListVariable 尚不兼容多个实体 类。