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     
    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

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.