DRL Rule to ensure no more than five night shifts in One Month per employee

I am trying to write rule to limit the number of night shifts completed by each employee within a month. The contractual requirement is än employee should not exceed 5 nights shift in total over a 28 day shift cycle".

I have tired using the below approach with limited success.. Any suggestions welcome

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

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

        int totalInt = $total.intValue();
        if ($contractLine.isMinimumEnabled() && totalInt < $contractLine.getMinimumValue()) {
                    (totalInt - $contractLine.getMinimumValue()) * $contractLine.getMinimumWeight());
        } else if ($contractLine.isMaximumEnabled() && totalInt > $contractLine.getMaximumValue()) {
                    ($contractLine.getMaximumValue() - totalInt) * $contractLine.getMaximumWeight());
        } else {
            // Workaround for https://issues.jboss.org/browse/PLANNER-761
            scoreHolder.addSoftConstraintMatch(kcontext, 0);

1 answer

  • answered 2020-01-14 09:53 Geoffrey De Smet

    Starting from the nurserostering example, you should be able to select a night shift A and then accumulate all nights shift assigned to the same employee which date is after A and before A + 28 days. If that accumulate count is too many or too few, penalize a hard constraint.

    With ConstraintStreams, we're looking for easier and more efficient ways to express constraints like this.