如何将java约束翻译成drools语言

萨米尔·艾迪
Constraint roomConflict(ConstraintFactory constraintFactory) {
    // A room can accommodate at most one lesson at the same time.
    return constraintFactory
            // Select each pair of 2 different lessons ...
            .forEachUniquePair(Lesson.class,
                    // ... in the same timeslot ...
                    Joiners.equal(Lesson::getTimeslot),
                    // ... in the same room ...
                    Joiners.equal(Lesson::getRoom))
            // ... and penalize each pair with a hard weight.
            .penalize("Room conflict", HardSoftScore.ONE_HARD);
}
拉多万·塞内克

没有可用的自动翻译;该约束只需要在 Drools 语言中重新实现。

对于这个特定的约束,它会是这样的:

rule "room conflict"
    when
        Lesson($id : id, $timeslot : timeslot, $room : room)
        Lesson(id > $id, timeslot == $timeslot, room == $room)
    then
        scoreHolder.addHardConstraintMatch(kcontext, 1);
end

它实际上类似于最初的约束定义:我们对发生在同一房间和同一时间段的每一对两个不同的课程进行惩罚。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章