【问题标题】:Optaplanner produces only single chain solutionOptaplanner 只生产单链解决方案
【发布时间】:2023-03-18 06:41:01
【问题描述】:

我正在使用 Optaplanner 解决安装人员预订分配问题,这是一个链接问题,类似于车辆路线。安装程序(车辆)可能有多个预订(客户)分配给它。我需要实施该链,因为我需要评估一个预订与另一个预订特定订单的关系。 因此,我在我的解决方案中将 Booking 和 Installer 声明为 @PlanningEntityCollectionProperty。 Booking 和 Installer 都实现了 Standstill。但仅在 Booking 中,我为方法 getPreviousStandstill() 声明了 @PlanningVariable。

我的配置:

<solver>
  <!--<environmentMode>FAST_ASSERT</environmentMode>-->

  <!-- Domain model configuration -->
  <solutionClass>InstallationSolution</solutionClass>
  <entityClass>Standstill</entityClass>
  <entityClass>Booking</entityClass>



  <!-- Score configuration -->
  <scoreDirectorFactory>
    <scoreDefinitionType>HARD_SOFT</scoreDefinitionType>
    <!--<easyScoreCalculatorClass>org.optaplanner.examples.cloudbalancing.solver.score.CloudBalancingEasyScoreCalculator</easyScoreCalculatorClass>-->
    <!--<easyScoreCalculatorClass>org.optaplanner.examples.cloudbalancing.solver.score.CloudBalancingMapBasedEasyScoreCalculator</easyScoreCalculatorClass>-->
    <!--<incrementalScoreCalculatorClass>org.optaplanner.examples.cloudbalancing.solver.score.CloudBalancingIncrementalScoreCalculator</incrementalScoreCalculatorClass>-->
    <!--<scoreDrl>com/tmrnd/pejal/opta/solver/fulfillmentScoreRules.drl</scoreDrl>-->
    <initializingScoreTrend>ONLY_DOWN</initializingScoreTrend>
    <!--<assertionScoreDirectorFactory>-->
      <!--<easyScoreCalculatorClass>org.optaplanner.examples.cloudbalancing.solver.score.CloudBalancingMapBasedEasyScoreCalculator</easyScoreCalculatorClass>-->
    <!--</assertionScoreDirectorFactory>-->
  </scoreDirectorFactory>

  <!-- Optimization algorithms configuration -->
  <termination>
    <!-- <secondsSpentLimit>20</secondsSpentLimit>-->
    <unimprovedSecondsSpentLimit>15</unimprovedSecondsSpentLimit>
  </termination>
  <constructionHeuristic>
    <constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>

  </constructionHeuristic>
  <localSearch>
    <unionMoveSelector>
      <changeMoveSelector/>
      <swapMoveSelector/>
      <subChainChangeMoveSelector>
        <selectReversingMoveToo>true</selectReversingMoveToo>
      </subChainChangeMoveSelector>
      <subChainSwapMoveSelector>
        <selectReversingMoveToo>true</selectReversingMoveToo>
      </subChainSwapMoveSelector>
    </unionMoveSelector>
    <acceptor>
      <entityTabuSize>20</entityTabuSize>

    </acceptor>
    <forager>
      <acceptedCountLimit>1000</acceptedCountLimit>
    </forager>
  </localSearch>
</solver>

当我尝试solve() 时,我得到了一位安装人员,所有预订都分配给了他。我需要做些什么来改善这种情况?

【问题讨论】:

    标签: optaplanner chained


    【解决方案1】:

    我最初的猜测是 OptaPlanner 只知道 1 个锚点(1 个安装程序)。检查解决方案列表的大小是否大于 1。然后检查getter 是否有@ValueRangeProvider 以及该ValueRangeProvider 的id 是否添加到@PlanningEntity 的valueRangeProviderRefs 中。

    还要注意一个可能也适用于此处的常见陷阱(但如果您正确使用值范围提供程序,则不应该这样做):list.add(list) 而不是 list.addAll(list)

    【讨论】:

    • 我在getProblemFacts()中把facts.addAll()改成了facts.add(),但是还是有同样的问题。在我取消注释/将我的 @PlanningVariable 更改为 CHAINED 后,我也遇到了以下异常:原因:java.lang.IllegalStateException:本地搜索阶段以未初始化的解决方案开始。首先初始化解决方案。例如,首先运行构建启发式阶段。但是,在出现异常之前,程序记录了:构建启发式阶段 (0) 结束:总步数 (1456)、花费的时间 (15875)、最佳分数 (-2761hard/-195507soft)。
    • 我认为是时候回到阅读文档而不是进行随机更改了 :) 特别是阅读有关链式变量等的规划配置一章。
    • 谢谢。我想我一定已经阅读了以前版本的文档,并且感到困惑。顺便说一句,我目前使用的是 6.1.0 Final 版本。你是对的,我改回了facts.addAll()。昨天测试时,我调整了 scoreDrl 中的分数(硬/软),然后开始了。从现在开始,我将微调我的 scoreDrl。
    猜你喜欢
    • 2014-12-20
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 2022-07-22
    • 2016-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多