我在理解在一个OptaPlanner演示示例(NurseRostering应用程序)中实现的Drools规则时遇到了问题。任何人都可以解释以下规则如何运作:
// a nurse can only work one shift per day, i.e. no two shift can be assigned to the same nurse on a day.
rule "oneShiftPerDay"
when
$leftAssignment : ShiftAssignment($leftId : id, $employee : employee, $shiftDate : shiftDate)
$rightAssignment : ShiftAssignment(employee == $employee, shiftDate == $shiftDate, id > $leftId)
then
insertLogical(new IntConstraintOccurrence("oneShiftPerDay", ConstraintType.NEGATIVE_HARD,
1,
$leftAssignment, $rightAssignment));
end
是否有任何资源详细说明规则的解释及其实施方式?当我在网上和一些书中查看一些例子时,我发现它很容易理解,但是当我查看Drools提供的样本时,我无法理解。
答案 0 :(得分:0)
when
// When a specific shift with id $leftId is assigned to employee $employee and that shift is on date $shiftDate
$leftAssignment : ShiftAssignment($leftId : id, $employee : employee, $shiftDate : shiftDate)
// AND there is another shift assigned to the same for the same date and with a higher id
$rightAssignment : ShiftAssignment(employee == $employee, shiftDate == $shiftDate, id > $leftId)
then
// Then this solution is penalized: it gets -1 hard score point
scoreHolder.addHardConstraintMatch(kcontext, -1);
注意:在那时,我使用了OptaPlanner 6语法(而不是弃用的Planner 5.x语法),因为它是faster and easier。
关于id < $leftId
部分:这是为了确保Drools只将ShiftAssignment A与ShiftAssignment B(给出A-B)而不是A-A,B-B,B-A匹配,以避免过多惩罚。
答案 1 :(得分:0)
为了学习DRL的语法,我建议在这里阅读Drools文档:
http://docs.jboss.org/drools/release/6.0.0.CR1/drools-expert-docs/html/ch04.html
根据我的理解,它对OptaPlanner / Drools Planner Docs的规则设置有所帮助。