0

I am facing issues in understanding the Drools rules which are implemented in one of the OptaPlanner demo example (NurseRostering application). Can anyone explain how the below rule works :

// 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

Are there any resources which states in detail about the explanation of the rules and the way they are implemented? When I check some of the examples online and in some books, i find it pretty easy to understand, however when i check the samples provided in Drools, i am unable to get an idea.

4

2 回答 2

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);

注意:在 then 方面,我使用了OptaPlanner 6 语法(而不是已弃用的 Planner 5.x 语法),因为它更快更容易

关于id < $leftId部分:这是为了确保 Drools 仅将 ShiftAssignment A 与 ShiftAssignment B(给出 AB)而不是 AA、BB、BA 匹配,以避免过多的惩罚。

于 2013-06-26T06:47:52.440 回答
0

为了学习 DRL 的语法,我建议在这里阅读 Drools 文档:

http://docs.jboss.org/drools/release/6.0.0.CR1/drools-expert-docs/html/ch04.html

据我了解,它对我的​​帮助比关于规则设置的 OptaPlanner/Drools Planner Docs 更多。

于 2013-08-22T08:02:57.893 回答