[英]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.