【问题标题】:Explanation of Drools Rules in NurseRostering applicationNurseRostering 应用程序中 Drools 规则的解释
【发布时间】:2013-06-25 17:31:20
【问题描述】:

我在理解 Drools 规则时遇到问题,这些规则在 OptaPlanner 演示示例之一(NurseRostering 应用程序)中实现。谁能解释以下规则的工作原理:

// 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 中提供的示例时,我无法理解。

【问题讨论】:

    标签: drools rules optaplanner


    【解决方案1】:
    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 语法),因为它是 faster and easier

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

    【讨论】:

      【解决方案2】:

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

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

      据我了解,它比 OptaPlanner/Drools Planner 文档对规则设置的帮助更多。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-11
        • 1970-01-01
        • 2014-04-17
        • 1970-01-01
        • 2021-12-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多