规划单位可以参考其他规划单位吗?

问题描述 投票:0回答:1

一个规划实体可以引用另一个规划实体并在分数计算中依赖于另一个实体吗?

示例: A

Lecture
要么设置了计划变量
Timeslot startTime
,要么引用了另一个讲座
Lecture sameStartTimeAsOtherLecture

执行分数计算(Bavet)时,冲突规则可能会从引用的

Lecture
中获取开始时间。

这样设置可以吗?

问题的原因:在我看来,增量分数计算取决于了解哪些实体发生了变化,并且我认为上面建议的设置可能有问题,因为

Lecture
的约束的有效性可能根据不同
Lecture
的更新进行更改。

如果不行,有推荐的解决方法吗?

optaplanner timefold
1个回答
0
投票

您所描述的情况是可以的,假设您在约束中引用了两个实体。考虑以下约束:

forEach(Lecture.class)
    .filter(lecture -> lecture.otherLecture().getStartTime() > ...)
    ...

如果

lecture
otherLecture
都是
Lecture
类型,则一切都很好。
forEach()
将确保约束在每个
Lecture
的每次更改时触发,因此将重新评估过滤器。

但是,如果

lecture
otherLecture
属于不同类型,这会导致我内部称之为“传递分数损坏”的情况。
forEach(...)
只会更新对
lecture
的更改,但对
otherLecture
的更改不会重新触发对此约束的重新评估,因此会导致分数损坏。

此问题的解决方案是使用

join
:

明确标记此类类型以进行重新评估
forEach(Lecture.class)
    .join(OtherLecture.class,
         Joiners.equal(Lecture::otherLecture(), Function.identity())
    .filter((lecture, otherLecture) -> otherLecture().getStartTime() > ...)
    ...
© www.soinside.com 2019 - 2024. All rights reserved.