How rules work
Rules are passed toModelBuilder as ruleConfigs, an array of { name, config } entries. Each rule compiles into CP-SAT constraints during builder.compile().
Priority levels
Each rule has apriority that determines how the solver treats it:
| Priority | Behavior |
|---|---|
MANDATORY | Hard constraint. The solver will never violate it, even if it means no solution is found |
HIGH | Soft constraint with high penalty. Strongly preferred but can be violated |
MEDIUM | Soft constraint with medium penalty |
LOW | Soft constraint with low penalty (nice to have) |
Built-in rules
Hours limits
| Rule | Description |
|---|---|
max-hours-week | Maximum hours per employee per week |
min-hours-week | Minimum hours per employee per week |
max-hours-day | Maximum hours per employee per day |
min-hours-day | Minimum hours per employee per day |
Consecutive days
| Rule | Description |
|---|---|
max-consecutive-days | Maximum consecutive working days |
min-consecutive-days | Minimum consecutive working days (avoid isolated single days) |
Shift limits
| Rule | Description |
|---|---|
max-shifts-day | Maximum number of shifts per employee per day |
min-rest-between-shifts | Minimum rest hours between consecutive shifts |
Time off
| Rule | Description |
|---|---|
time-off | Block specific dates/times for an employee |
Assignment
| Rule | Description |
|---|---|
assign-together | Keep specific employees on the same shifts |
employee-assignment-priority | Prefer certain employees for certain roles/times |
location-preference | Prefer employees at specific locations |
Scoping
Rules can be scoped to apply to specific subsets of employees or time periods. Use thescope field:
employeeIds: apply to specific employeesroleIds: apply to employees with specific rolesskillIds: apply to employees with specific skillsdays: apply only on specific datesdaysOfWeek: apply only on specific days of the week