员工名册示例的编辑规则

时间:2018-09-12 06:52:39

标签: optaplanner rostering optaweb-employee-rostering

我目前正在为我的项目实施this

我需要为“每位员工每周最多四个轮班分配”添加一条规则。我是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

1 个答案:

答案 0 :(得分:1)

您可以尝试使用accumulate

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

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