繁体   English   中英

员工排班示例的编辑规则

[英]Editing rules for employee rostering example

我目前正在为我的项目实施程序。

我需要为“每位员工每周最多四个班次分配”添加一条规则。 我是java和drool的新手。 有没有一种简单的方法可以编辑以下规则以匹配我要寻找的约束?

rule "At most one shift assignment per day per employee"
when
    $s : Shift(
            employee != null,
            $e : employee,
            $leftDay : startDateTime.toLocalDate())
    Shift(
            employee == $e,
            startDateTime.toLocalDate() == $leftDay,
            this != $s)
then
    scoreHolder.addHardConstraintMatch(kcontext, -10);
end

您可以尝试使用累加

您的规则可能看起来像这样(我尚未测试过,但是它应该为您指明正确的方向):

rule "At most four shift assignment per week per employee"
when
    $shiftWeek: ShiftWeek() //assuming this is some kind of problemfact you have in your session
    $employee: Employee()
    $count: Number(intValue() > 4) //conditional, only fire rule when $count > 4
        from accumulate(
            $shift: Shift(
                $employee == employee,
                $shiftWeek == shiftWeek
            ),
            count($shift)
        )
then
    scoreHolder.addHardConstraintMatch(kcontext, 4 - $count.intValue()); //You could also just do "- $count.intValue()", but I like the constraint match to start at -1
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM