【问题标题】:Get identifiers of entities violating constraints获取违反约束的实体的标识符
【发布时间】:2022-01-07 05:47:38
【问题描述】:
我的问题是在 N 天的时间表中安排约会。我知道,对于一些非常不利的情况,我永远找不到不违反约束的解决方案。
我想做的是在问题上运行求解器,获取违反硬约束的约会,将它们从解决方案中删除,然后在接下来 N 天的时间表上使用这些约会重新执行求解器(即重新安排它们)。
有没有办法获取违反约束的约会标识符并将其从 Java 解决方案中删除?我阅读了文档,但没有找到任何东西。
【问题讨论】:
标签:
java
scheduling
optaplanner
【解决方案1】:
寻找Constraint Justification。
您不一定会收到实体,但您会收到导致惩罚的对象。考虑以下约束:
Constraint computerCost(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(CloudComputer.class)
.ifExists(CloudProcess.class, equal(Function.identity(), CloudProcess::getComputer))
.penalize("computerCost",
HardSoftScore.ONE_SOFT,
CloudComputer::getCost);
}
约束理由将包括被惩罚的CloudComputer。 (约束流是UniConstraintStream<CloudComputer>。)约束理由将不包括CloudProcess,因为它不计入惩罚。