有没有办法在施工阶段使用 sorterClass ?

Is there a way to use sorterClass during construction phase?

问题概述:

我们正在为用户分配任务 只能将一项任务分配给用户 任务可以是可变长度:1-16 小时 用户一次只能执行一项任务 用户每天有 8 小时 我们正在使用时间颗粒模式 - 1 颗粒 = 1 小时。 由于任务的长度可变,并非所有 TimeGrains 都用于给定用户

使用默认排序不会return在 10 分钟内得到解决方案。

我使用以下配置取得了一些成功(结果 return 在几秒钟内完成)

  <constructionHeuristic>
    <changeMoveSelector>
      <selectionOrder>RANDOM</selectionOrder>
      <selectedCountLimit>300</selectedCountLimit>
      <valueSelector variableName="user"/>
    </changeMoveSelector>
    <changeMoveSelector>
      <valueSelector variableName="startDate"/>
    </changeMoveSelector>
  </constructionHeuristic>

然而这似乎导致任务分配不均。我尝试实现自定义排序,即

<sorterClass>com.example.UserSelectionSorter</sorterClass>

但这会产生以下错误:

Exception in thread "main" java.lang.IllegalStateException: Replay must occur after record. The recordingEntitySelector (Recording(FromSolutionEntitySelector(SubTask)))'s hasNext() has not been called yet.
        at org.optaplanner.core.impl.heuristic.selector.entity.mimic.MimicReplayingEntitySelector$ReplayingEntityIterator.hasNext(MimicReplayingEntitySelector.java:117)
        at org.optaplanner.core.impl.heuristic.selector.common.iterator.AbstractOriginalChangeIterator.createUpcomingSelection(AbstractOriginalChangeIterator.java:47)
        at org.optaplanner.core.impl.heuristic.selector.common.iterator.AbstractOriginalChangeIterator.createUpcomingSelection(AbstractOriginalChangeIterator.java:26)
        at org.optaplanner.core.impl.heuristic.selector.common.iterator.UpcomingSelectionIterator.hasNext(UpcomingSelectionIterator.java:43)
        at java.base/java.util.Iterator.forEachRemaining(Iterator.java:132)
        at org.optaplanner.core.impl.heuristic.selector.move.decorator.AbstractCachingMoveSelector.constructCache(AbstractCachingMoveSelector.java:77)
        at org.optaplanner.core.impl.heuristic.selector.move.decorator.SortingMoveSelector.constructCache(SortingMoveSelector.java:43)
        at org.optaplanner.core.impl.heuristic.selector.common.SelectionCacheLifecycleBridge.phaseStarted(SelectionCacheLifecycleBridge.java:51)
        at org.optaplanner.core.impl.phase.event.PhaseLifecycleSupport.firePhaseStarted(PhaseLifecycleSupport.java:37)
        at org.optaplanner.core.impl.heuristic.selector.AbstractSelector.phaseStarted(AbstractSelector.java:50)
        at org.optaplanner.core.impl.phase.event.PhaseLifecycleSupport.firePhaseStarted(PhaseLifecycleSupport.java:37)
        at org.optaplanner.core.impl.heuristic.selector.AbstractSelector.phaseStarted(AbstractSelector.java:50)
        at org.optaplanner.core.impl.phase.event.PhaseLifecycleSupport.firePhaseStarted(PhaseLifecycleSupport.java:37)
        at org.optaplanner.core.impl.constructionheuristic.placer.AbstractEntityPlacer.phaseStarted(AbstractEntityPlacer.java:44)
        at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.phaseStarted(DefaultConstructionHeuristicPhase.java:118)
        at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.solve(DefaultConstructionHeuristicPhase.java:65)
        at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:99)
        at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:192)
        at com.example.App.main(App.java:50) 

advanced configuration of a Construction heuristic。这明确地写了模仿 recording/replay 。这允许您进入第一个 entitySelector(所以不是 ref )并在那里使用 sorterClass。