问题描述
我正在构建一个学生时间表生成器,我需要一种产生多个解决方案的方法.有什么方法可以节省可行分数或Xhard/Ysoft分数吗?
I'm building a student schedule generator and I need a way of producing more than one solution. Is there some way to save off feasible scores or scores of Xhard/Ysoft?
我需要能够输出多个潜在的时间表,这样,无论出于何种原因,学生都不愿意最佳"时间表(也许他们不希望这样做),学生可以选择一个时间表而不是另一个时间表.就像其中一位教授一样,也许他们不希望早上8点上课)
I need to be able to output more than one potential schedule, that way the student will have a choice for one schedule over the other if for whatever reason they don't want the "best" schedule (maybe they don't like one of the professors, maybe they don't want an 8am class, whatever)
我最初的想法是使用bestSolutionChanged事件侦听器保存所有可行的解决方案.问题在于,一旦找到0hard/0soft分数,它将忽略此后的所有分数,包括相等的分数.
My original idea was to save off all feasible solutions using the bestSolutionChanged event listener. The problem with this, is that once it finds a 0hard/0soft score, it ignores all scores after that, including scores that are equal.
理想情况下,我想保留所有0hard/-3soft或更好的分数,但是能够保存任何可行的分数或迫使optaplanner寻找新的最佳分数也是有用的.
Ideally I'd like to save off all scores of 0hard/-3soft or better, but just being able to save any feasible scores or force optaplanner to look for a new best score would be useful as well.
推荐答案
这不是解决方案,而是对问题的分析:
This is not a solution, but an analysis of the problem:
破解BestSolutionRecaller
显然不仅仅是一个大麻烦,而且这也是我们不希望鼓励的行为,因为这会使升级到新版本变得更大.因此,不要指望我们通过添加一种简单的方法来解决此问题,因为该方法会很快在解决程序配置中进行配置.话虽这么说,显然需要解决这个常见问题的方法.
Hacking the BestSolutionRecaller
is obviously not just a big pain, it's also behaviour we don't want to encourage as it makes upgrading to newer version an even bigger pain. So don't expect us to solve this by adding an easy way to configure that in the solver config any time soon. That being said, a solution for this common problem is clearly needed.
找到新的最佳解决方案时,将从工作解决方案(OptaPlanner中的内部解决方案)中计划克隆(请参阅文档以获取定义).这使我们能够记住随着工作解决方案的变化而出现的最佳新解决方案.这也意味着BestSolutionChangedEvents获得了 plannng克隆,并且可以安全地将其发送到另一个线程,例如,将其封送给客户端(假定您创建的所有ProblemFactChange
做副本而不是更改),而无需被修改工作解决方案的求解器线程破坏.
When a new best solution is found, it is planning cloned (see docs for definition) from the working solution (the internal solution in OptaPlanner). This allow us to remember that new best solution as the working solution solution changes. That also means the BestSolutionChangedEvents gets a plannng clone and can safely ship it to another thread, for example to marshal it to a client (presuming any ProblemFactChange
s you create do copies instead of alterations), without being corrupted by the solver thread that modifies the working solution.
新的最佳解决方案暗示workingScore > bestScore
.相反,当它执行workingScore >= bestScore
时,我们需要更多的计划克隆(这会占用大量CPU),但是我们也可以为此而发送BestSolutionChangedEvents,如果且仅当启用了标志时当然,因为大多数用户(与您不同)不希望这种行为.
New best solution imply that workingScore > bestScore
. The moment it instead does workingScore >= bestScore
, we need far more planning clones (which are a bit CPU expensive), but we could then just send out BestSolutionChangedEvents for that too, if and only if a flag is enabled of course, because most users (unlike yourself) don't want this behaviour.
一个建议是在BestSolutionChangedEvent
旁边创建一个单独的BestSolutionChangedOrSameEvent
.这可能不是理想的,因为我们需要能够检测是否有人需要这些额外的计划克隆.
One proposal is to create a separate BestSolutionChangedOrSameEvent
, next to the BestSolutionChangedEvent
. This might not be ideal, because we need to be able to detect whether or not someone needs those extra planning clones.
另一个建议是在<solver>
配置中仅包含一个标志,该标志将从>
切换为>=
的行为.
Another proposal is to just have a flag in the <solver>
config that switches from >
to >=
behavior for BestSolutionChangedEvent
.
请创建一个jira(请参见网页上的获得帮助")并在此处链接它,或者创建支持票证(另请参见网页上的获得帮助").
Please create a jira (see "get help" on webpage) and link it it here, or create a support ticket (also see "get help" on webpage).
这篇关于有没有办法保存找到的所有可行分数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!