OptaPlanner 返回最佳分数,但不返回其相关解决方案 [英] OptaPlanner return the best score but not its associated solution

查看:67
本文介绍了OptaPlanner 返回最佳分数,但不返回其相关解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 OptaPlanner 7.33.0 解决 CloudBalancing 等问题.

I'm working on a problem like CloudBalancing with OptaPlanner 7.33.0.

返回的 PlanningSolution 对象包含最佳计算分数,但解决方案不匹配.我用一个非常小的数据集调试了所有解决方案,返回的解决方案似乎是最新的,它没有返回的分数.

The returned PlanningSolution object contains the best calculated score but the solution does not match. I debugged all solutions with a very small dataset and the returned solution seems to be the latest that it doesn't have the returned score.

示例:

  • 1:得分最高的解决方案的得分为 0hard/-1197medium/4soft
  • 2:返回的解决方案的得分为 0hard/-1198medium/2soft
  • 求解器返回一个 PlanningSolution 对象,其中包含解决方案 1 的分数,但包含解决方案 2 的内容

这是我的规划解决方案课

This is my planning solution class

@PlanningSolution
public class GroupSolution
{
    @PlanningEntityCollectionProperty
    private List<Request> request;

    @ValueRangeProvider(id = "groupRange")
    @ProblemFactCollectionProperty
    private List<Group> proposedGroups;

    @PlanningScore
    private HardMediumSoftScore score;

    // Others planning fact that I use in my EasyScoreCalculator
}

请求类

@PlanningEntity
public class Request
{
    @PlanningVariable(valueRangeProviderRefs = {
        "groupRange"
    }, nullable = false)
    private Group group;

    // Other properties
}

配置

<?xml version="1.0" encoding="UTF-8"?>
<solver>
  <scanAnnotatedClasses>
    <packageInclude>my.package.domain</packageInclude>
  </scanAnnotatedClasses>

  <!-- Score configuration -->
  <scoreDirectorFactory>
    <initializingScoreTrend>ONLY_DOWN</initializingScoreTrend>
    <easyScoreCalculatorClass>my.package.MyEasyScoreCalculator</easyScoreCalculatorClass>
  </scoreDirectorFactory>

  <constructionHeuristic />

  <termination>
    <minutesSpentLimit>5</minutesSpentLimit>
  </termination>
</solver>

我使用的是具有 3 个评分级别的 EasyScoreCalculator,我是这样使用它们的:

I'm using an EasyScoreCalculator with 3 levels of scoring and I use them like this :

  • hard :我只将它设置为 0 或 -1.如果 -1 我不计算其他分数为 -1 表示该解决方案不适用
  • medium :价格,例如如果解决方案花费 100 欧元,我的中等分数将为 -100
  • soft :如果 2 个价格相同,我使用这个分数来首选具有更多空组的解决方案(每个组的最大请求数).这个分数从不为负

我将继续对此进行调查,但如果您有任何建议以获得正确的结果,您可以告诉我.

I will continue to investigate on this but if you have any suggestion to get the correct result you can tell me.

但主要问题是,您知道这是否是 OptaPlanner 的正常行为吗?如果是正常的,他会返回一个不匹配的分数和解决方案吗?

But the main question is, do you know if it's a normal OptaPlanner behavior or not? If it's normal in which case he will return a non matching score and solution?

推荐答案

1) 听起来像是分数损坏.鉴于 FAST_ASSERT修复它"(它没有),使用 NON_INTRUSIVE_FULL_ASSERT 运行它,如果它抛出异常,它可能会指向真正的问题,因为它更早地检测到问题.

1) Sounds like score corruption. Given that FAST_ASSERT "fixes it" (it doesn't), run it with <environmentMode>NON_INTRUSIVE_FULL_ASSERT</environmentMode>, if it throws an exception, it might point you to the real problem, because it detects the issue earlier.

2) 也可能是由于计划实体克隆损坏.这更难检测.您是否使用自定义解决方案克隆器?是否有任何域类引用了规划实体类或规划解决方案(因此引用了 RequestGroupSolution)?任何具有带有 RequestGroupSolution 实例的 Collection 或 Map 的类?

2) Could also be due to planning entity cloning corruption. That's harder to detect. Do you use a custom solution cloner? Are there any domain classes that have references to the planning entity class(es) or planning solution (so references Request or GroupSolution)? Any classes that have a Collection or Map with Request or GroupSolution instances?

这篇关于OptaPlanner 返回最佳分数,但不返回其相关解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆