如何将 java 约束翻译成流口水语言
how to translate a java constraint into drools language
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 语言中,约束必须是 re-implemented。
对于这个特定的约束,应该是这样的:
rule "room conflict"
when
Lesson($id : id, $timeslot : timeslot, $room : room)
Lesson(id > $id, timeslot == $timeslot, room == $room)
then
scoreHolder.addHardConstraintMatch(kcontext, 1);
end
它实际上类似于原始约束定义:我们对在同一房间和同一时间段上课的每一对两个不同的课程进行惩罚。
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 语言中,约束必须是 re-implemented。
对于这个特定的约束,应该是这样的:
rule "room conflict"
when
Lesson($id : id, $timeslot : timeslot, $room : room)
Lesson(id > $id, timeslot == $timeslot, room == $room)
then
scoreHolder.addHardConstraintMatch(kcontext, 1);
end
它实际上类似于原始约束定义:我们对在同一房间和同一时间段上课的每一对两个不同的课程进行惩罚。