optaplanner - 员工排班示例的编辑规则
问题描述
我目前正在为我的项目实施这个。
我需要为“每位员工每周最多四次轮班分配”添加一条规则。我是 Java 和流口水的新手。有没有一种简单的方法来编辑下面的规则以匹配我正在寻找的约束?
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
推荐阅读
- macos - 解决警告 NETSDK1138:目标框架“netcoreapp3.0”不受支持
- node.js - “node_modules\uuidv4\build\lib\uuidv4.js”的包试图导入Node标准库模块“util”
- python - 循环字典列表并比较其他列表中的任何匹配值
- asp.net-mvc - 在 Asp.net Mvc 5 中使用 Active Directory 登录?
- vim - 维姆。无法将非英语字符拉到系统剪贴板
- regex - 正则表达式提取包含 PIPE (|) 的子字符串
- python - check if key is present in the row as a substring
- scala - Spark union taking a long time with 1 long-running task
- node.js - 节点 express req.body 返回空 obj
- android - I am having troubles creating a Marker on flutter with the Google Maps dependency