10.2.5.2. Creating a guided rule to balance employee shift numbers
The BalanceEmployeesShiftNumber guided rule creates a soft constraint that ensures shifts are assigned to employees in a way that is balanced as evenly as possible. It does this by creating a score penalty that increases when shift distribution is less even. The score formula, implemented by the rule, incentivizes the Solver to distribute shifts in a more balanced way.
Procedure
-
In Business Central, go to Menu
Design Projects and click the project name. -
Click Add Asset
Guided Rule. -
Enter
BalanceEmployeesShiftNumberas the Guided Rule name and select theemployeerostering.employeerosteringPackage. - Click Ok to create the rule asset.
-
Add a WHEN condition by clicking the
in the WHEN field.
-
Select
Employeein the Add a condition to the rule window. Click +Ok. -
Click the
Employeecondition to modify the constraints and add the variable name$employee. Add the WHEN condition
From Accumulate.-
Above the
From Accumulatecondition, click click to add pattern and selectNumberas the fact type from the drop-down list. -
Add the variable name
$shiftCountto theNumbercondition. -
Below the
From Accumulatecondition, click click to add pattern and select theShiftAssignmentfact type from the drop-down list. -
Add the variable name
$shiftAssignmentto theShiftAssignmentfact type. -
Click the
ShiftAssignmentcondition again and from the Add a restriction on a field drop-down list, selectemployee. -
Select
equal tofrom the drop-down list next to theemployeeconstraint. -
Click the
icon next to the drop-down button to add a variable, and click Bound variable in the Field value window.
-
Select
$employeefrom the drop-down list. -
In the Function box type
count($shiftAssignment).
-
Above the
-
Add the THEN condition by clicking the
in the THEN field.
Select
Modify Soft Scorein the Add a new action window. Click +Ok.-
Type the following expression into the box:
-($shiftCount.intValue()*$shiftCount.intValue())
-
Type the following expression into the box:
- Click Validate in the upper-right corner to check all rule conditions are valid. If the rule validation fails, address any problems described in the error message, review all components in the rule, and try again to validate the rule until the rule passes.
- Click Save to save the rule.
For more information about creating guided rules, see Designing a decision service using guided rules.