Chapter 5. Employee rostering constraints

Employee rostering is a planning problem. All planning problems include constraints that must be satisfied in order to find an optimal solution.

The employee rostering sample project in Decision Central includes the following hard and soft constraints:

Hard constraint
  • Employees are only assigned one shift per day.
  • All shifts that require a particular employee skill are assigned an employee with that particular skill.
Soft constraints
  • All employees are assigned a shift.
  • If an employee requests a day off, their shift can be reassigned to another employee.

Hard and soft constraints can be defined in Decision Central using either the free-form DRL designer, or using guided rules.

For more information about hard and soft constraints, see Installing and configuring Red Hat Business Optimizer.

5.1. DRL rules

DRL rules are business rules that you define directly in .drl text files. These DRL files are the source in which all other rule assets in Decision Central are ultimately rendered. You can create and manage DRL files within the Decision Central interface, or create them externally using Red Hat Developer Studio, Java objects, or Maven archetypes. A DRL file can contain one or more rules that define at minimum the rule conditions (when) and actions (then). The DRL designer in Decision Central provides syntax highlighting for Java, DRL, and XML.

All data objects related to a DRL rule must be in the same project package as the DRL rule in Decision Central. Assets in the same package are imported by default. Existing assets in other packages can be imported with the DRL rule.

5.2. Constraint definition for employee rostering using the DRL designer

You can create constraint definitions for the employee rostering example using the free-form DRL designer in Decision Central.

Use this procedure to create a hard constraint where no employee can be assigned a shift that begins less than 10 hours after their previous shift ended.

Procedure

  1. Go to MenuDesignProjects and click the project name.
  2. Click Create New AssetDRL file.
  3. In the DRL file name field, type ComplexScoreRules.
  4. Select the employeerostering.employeerostering package.
  5. Click +Ok to create the DRL file.
  6. In the Editor tab of the DRL designer, define the Employee10HourShiftSpace rule as a DRL file:

    package employeerostering.employeerostering;
    
    rule "Employee10HourShiftSpace"
        dialect "mvel"
        when
            $shiftAssignment : ShiftAssignment( $employee : employee != null, $shiftEndDateTime : shift.timeslot.endTime)
            ShiftAssignment( this != $shiftAssignment, $employee == employee, $shiftEndDateTime <= shift.timeslot.endTime,
                    $shiftEndDateTime.until(shift.timeslot.startTime, java.time.temporal.ChronoUnit.HOURS) <10)
        then
            scoreHolder.addHardConstraintMatch(kcontext, -1);
    end
  7. Click Save to save the DRL file.

For more information about creating DRL files, see Designing a decision service using DRL rules.