DRL规则,以确保每位员工每月不超过五个夜班

问题描述 投票:0回答:1

我正在尝试编写规则以限制每个员工在一个月内完成的夜班次数。合同规定,在28天的轮班中,员工的轮班总数不得超过5晚”。

我厌倦了使用以下方法获得有限的成功。欢迎任何建议

rule "minimumConsecutiveNightShifts"
      salience 1     
    when
        $contractLine : MinMaxContractLine(contractLineType == ContractLineType.TOTAL_NIGHT_ASSIGNMENTS, enabled == true,
            $contract : contract)
        $employee : Employee(contract == $contract)
         $shiftType : ShiftType(night == true)

        accumulate(
            $assignment : ShiftAssignment(employee == $employee, shiftType == $shiftType);
            $total : count($assignment)

        )
   then
        int totalInt = $total.intValue();
        System.out.println($contract);
        if ($contractLine.isMinimumEnabled() && totalInt < $contractLine.getMinimumValue()) {
            scoreHolder.addSoftConstraintMatch(kcontext,
                    (totalInt - $contractLine.getMinimumValue()) * $contractLine.getMinimumWeight());
        } else if ($contractLine.isMaximumEnabled() && totalInt > $contractLine.getMaximumValue()) {
            scoreHolder.addSoftConstraintMatch(kcontext,
                    ($contractLine.getMaximumValue() - totalInt) * $contractLine.getMaximumWeight());
        } else {
            // Workaround for https://issues.jboss.org/browse/PLANNER-761
            scoreHolder.addSoftConstraintMatch(kcontext, 0);
        }
end
java optaplanner
1个回答
0
投票

[从提供护士的例子开始,您应该能够选择一个夜班A,然后累积分配给同一员工的所有夜班,该日期在A之后,在A + 28天之前。如果该累加计数太多或太少,则对硬约束进行惩罚。

使用ConstraintStreams,我们正在寻找更轻松,更有效的方式来表达这样的约束。

© www.soinside.com 2019 - 2024. All rights reserved.