Constraints
1. Overview
Constraints can be considered hard, medium, or soft.
Hard constraints represent rules and limitations of the real world that any planning solution has to respect. For instance, there are only 24 hours in a day and people can only be in one place at a time. Hard constraints also include rules that must be adhered to, for instance, employees must have certain skills to be assigned to specific shifts.
Breaking hard constraints results in infeasible plans.
Medium constraints help manage plans when resources are limited, for instance, assign as many mandatory shifts as possible. Medium constraints incentivize Timefold Platform to assign as many shifts as possible.
Soft constraints help optimize plans based on the business goals, for instance, keeping costs per period in a preferred range.
To help determine the quality of solutions, plans are assigned a score with values for hard, medium, and soft constraints.
0hard/-257medium/-6119520soft
Timefold examines many solutions during solving and is incentivized to use the solution with the highest score.
From the example score above, you can see zero hard constraints were broken, while both the medium and soft scores have negative values (the scores do not show how many constraints were broken, but values associated with those constraints).
Because breaking hard constraints would result in an infeasible solution, a solution that breaks zero hard constraints and has a soft constraint score of -1,000,000 is better than a solution that breaks 1 hard constraint but has a soft constraint score of 0.
It’s important to note that constraints have competing goals, for instance, a constraint that is concerned with fairness or load balancing may result in a solution that takes longer to execute, whereas constraints concerned with shortening the overall solution time may result in a solution that isn’t fairly disrupted among the available resources.
Timefold balances the competing priorities of constraints to arrive at solutions with the best overall score.
2. Employee shift scheduling constraint groups and constraints
Constraints are grouped together with similar constraints into constraint groups. The following constraint groups and constraints are available in employee shift scheduling.
2.1. Alternative shifts
The constraint in this group is designed to create multiple variants of a shift and make sure a specific number of the variants are assigned.
The following constraint is part of the Alternative shifts constraint group.
-
Required shift group assignment mode not met
For more information about this constraint group see the Alternative shifts guide.
2.2. Cost management
The constraints in this group are designed to keep the cost of staffing all shifts within budget.
The following constraints are part of the Cost management constraint group.
-
Costs per period not in preferred range
-
Costs per period not in required range
For more information about this constraint group see the Cost management guide.
2.3. Demand-based scheduling
The constraints in this group are designed to manage the number of assigned shifts and evenly spread the assigned shifts across periods of demand.
The following constraints are part of the Demand-based scheduling constraint group.
-
Balance shifts worked for minimum hourly demand
-
Shifts worked not in preferred hourly demand range
-
Shifts worked not in required hourly demand range
For more information about this constraint group see the Demand-based scheduling guide.
2.4. Employee availability
The constraints in this group are designed to only assign employees to shifts when they are available, and take employee preferences into consideration when making assignments.
The following constraints are part of the Employee availability constraint group.
-
Employee does not work during available time
-
Employee works during preferred time
-
Employee works during unavailable time
-
Employee works during unpreferred time
-
Employee works shift with non-matching required shift tags
-
Employee works shift with preferred shift tags
For more information about this constraint group see the Employee availability guide.
2.5. Fairness
The constraints in this group are designed to distribute work fairly across all employees.
The following constraints are part of the Fairness constraint group.
-
Balance shift count
-
Balance time worked
For more information about this constraint group see the Fairness guides.
2.6. Pairing employees
The constraints in this group are designed to manage how employees are paired (or not) on shifts.
The following constraints are part of the Pairing employees constraint group.
-
Employee is not paired with required employee
-
Employee is paired with preferred employee
-
Employee is paired with prohibited employee
-
Employee is paired with unpreferred employee
For more information about this constraint group see the Pairing employees guide.
2.7. Replanning
The constraint in this group is designed to reduce disruptions to the original plan when replanning.
The following constraint is part of the Replanning constraint group.
-
Employee assignment disrupted on replanning
For more information about this constraint group see the Real-time planning guide.
2.8. Resource-limited planning
The constraints in this group are designed to schedule as much priority work as possible when there aren’t enough people to cover all the shifts.
The following constraints are part of the Resource-limited planning constraint group.
-
Unassigned mandatory shift
-
Unassigned optional shift
For more information about this constraint group see the Mandatory and optional shifts guide.
2.9. Shift assignments
The constraints in this group are designed to manage which employees should (preferably) be assigned and not assigned to certain shifts.
The following constraints are part of the Shift assignments constraint group.
-
Concurrent shifts worked not in required range
-
Preferred employee assigned
-
Prohibited employee assigned
-
Shifts worked per period not in preferred range
-
Shifts worked per period not in required range
-
Unpreferred employee assigned
For more information about this constraint group see the Shift assignments guide.
2.10. Shift rotations and patterns
The constraints in this group are designed to create schedules that respect employees' work-life balance.
The following constraints are part of the Shift rotations and patterns constraint group.
-
Custom rotation duration in days not in preferred range for employee
-
Custom rotation duration in days exceeds required maximum for employee
-
Do not assign employees to shifts if the difference between start times is greater than the limit specified
-
Employee does not have preferred daily shift pairing
-
Employee does not have required daily shift pairing
-
Employee does not work required multi day shift sequence pattern
-
Employee does not work required single day shift sequence pattern
-
Employee has prohibited daily shift pairing
-
Employee has unpreferred daily shift pairing
-
Employee works preferred multi day shift sequence pattern
-
Employee works preferred single day shift sequence pattern
-
Employee works prohibited multi day shift sequence pattern
-
Employee works prohibited single day shift sequence pattern
-
Employee works unpreferred multi day shift sequence pattern
-
Employee works unpreferred single day shift sequence pattern
-
Minimize gaps between shifts for employee
-
Minutes between shifts not in preferred range for employee
-
Minutes between shifts not in required range for employee
-
Overlapping shift
-
Preferred shift rotation not met for employee
-
Required shift rotation not met for employee
-
Shift start time difference in minutes per period not in preferred range for employee
For more information about this constraint group see the Shift rotations and patterns guides.
2.11. Shift travel and locations
The constraints in this group are designed to respect employees' shift location preferences and reduce the amount of time employees spend traveling to their shifts.
The following constraints are part of the Shift travel and locations constraint group.
-
Locations worked per period not in preferred range for employee
-
Locations worked per period not in required range for employee
-
Maximum employee to shift travel distance exceeded
-
Minimize travel distance
-
Minimum time between shifts including travel not met
For more information about this constraint group see the Shift travel and locations guide.
2.12. Shift type diversity
The constraints in this group are designed to control the number of different types of shifts and tasks employees can be assigned.
The following constraints are part of the Shift type diversity constraint group.
-
Shift types worked per period not in preferred range for employee
-
Shift types worked per period not in required range for employee
-
Unique tags per period not in preferred limit
-
Unique tags per period not in required limit
For more information about this constraint group see the Shift type diversity guides.
2.13. Skill and risk factors
The constraints in this group are designed to define skills and risk factors to make sure shifts are assigned to employees with the right qualifications and no risk factors.
The following constraints are part of the Skill and risk factors constraint group.
-
Employee has prohibited risk factor associated with shift
-
Preferred skill missing
-
Required skill missing
For more information about this constraint group see the Skills and risk factors guide.
2.14. Time off
The constraints in this group are designed to manage employees' time off
The following constraints are part of the Time off constraint group.
-
Consecutive days off per period not in preferred range for employee
-
Consecutive days off per period not in required range for employee
-
Consecutive days off in rolling window not in preferred range for employee
-
Consecutive days off in rolling window not in required range for employee
-
Consecutive minutes off in rolling window not in preferred range for employee
-
Consecutive minutes off in rolling window not in required range for employee
-
Days off per period not in preferred range for employee
-
Days off per period not in required range for employee
-
Employee has prohibited shift near day off request
-
Employee has unpreferred shift near day off request
For more information about this constraint group see the Time off guides.
2.15. Work limits
The constraints in this group are designed to manage employees' contractual hours.
The following constraints are part of the Work limits constraint group.
-
Consecutive days worked not in preferred range for employee
-
Consecutive days worked not in required range for employee
-
Consecutive weekends worked per period not in preferred range for employee
-
Consecutive weekends worked per period not in required range for employee
-
Days worked in rolling window not in preferred range for employee
-
Days worked in rolling window not in required range for employee
-
Days worked per period not in preferred range for employee
-
Days worked per period not in required range for employee
-
Employee works compact sequence
-
Minutes logged per period not in preferred range for employee
-
Minutes logged per period not in required range for employee
-
Minutes worked in rolling window not in preferred range for employee
-
Minutes worked in rolling window not in required range for employee
-
Minutes worked per period not in preferred range for employee
-
Minutes worked per period not in required range for employee
-
Preferred minimum time between different sequences not met for employee
-
Preferred sequence start day met for employee
-
Shifts worked in rolling window not in preferred range for employee
-
Shifts worked in rolling window not in required range for employee
-
Shifts worked per period not in preferred range for employee
-
Shifts worked per period not in required range for employee
-
Weekend minutes worked per period not in preferred range for employee
-
Weekend minutes worked per period not in required range for employee
-
Weekends worked in rolling window not in preferred range for employee
-
Weekends worked in rolling window not in required range for employee
-
Weekends worked per period not in preferred range for employee
-
Weekends worked per period not in required range for employee
For more information about this constraint group see the Work limits guides.
3. Constraint weights
Every constraint has a weight and a match score that will be applied to the dataset score every time the constraint is matched.
The final score for an instance of a constraint being matched is calculated by multiplying the constraint weight by the match score.
Active soft constraints have a default weight of 1, meaning that all soft constraints are equally weighted. Constraint weights can be changed to make some constraints more important than others.
A constraint with a weight of 10, increases the impact of the score by a factor of 10 (10 * match score).
When a constraint has a weight of 0, the constraint score has no impact.
The match score is derived from the penalty or reward constraints apply when they are matched.
For instance, the Minutes worked per period not in preferred range for employee
constraint adds a soft penalty that is derived from the additional minutes an employee works.
If a rule specifies an employee can work a maximum of 240 minutes per day, but the employee is assigned 300 minutes, the Minutes worked per period not in preferred range for employee
constraint will return a match score of -60.
If the minutesWorkedPerPeriodNotInPreferredRangeForEmployeeWeight
(which sets the weight of the Minutes worked per period not in preferred range for employee
constraint) is set to 1, the final soft score for this instance of the constraint matching will be -60.
If the minutesWorkedPerPeriodNotInPreferredRangeForEmployeeWeight
is set to 2, the final soft score for this instance of the constraint matching will be -120.
3.1. Constraint weight configuration
Constraint weights can be configured in individual input datasets or as part of a configuration profile that can be reused with future input datasets.
3.1.1. Configure a configuration profile
Constraint weights can be configured in Timefold Platform by creating a configuration profile and setting the weight in the configuration profile:
-
Log in to Timefold Platform: app.timefold.ai
-
Select the employee shift scheduling tile.
-
Select Configuration profiles.
-
Add a new configuration profile (or modify an existing profile) and configure the constraint weights.
The configuration profile can be specified when you submit a new dataset by appending a query parameter with the configuration profile name to the POST URL.
For instance, if the configuration profile is called test
, the query parameter would be: ?configurationId=test
Learn more about configuration parameters and profiles.
3.2. Available constraint weights
Constraint | Constraint weight |
---|---|
Balance shift count |
|
Balance shifts worked for minimum hourly demand |
|
Balance time worked |
|
Consecutive days off in rolling window not in preferred range for employee |
|
Consecutive days off per period not in preferred range for employee |
|
Consecutive days worked not in preferred range for employee |
|
Consecutive minutes off in rolling window not in preferred range for employee |
|
Consecutive weekends worked per period not in preferred range for employee |
|
Costs per period not in preferred range |
|
Custom rotation duration in days exceeds preferred maximum for employee |
|
Days off per period not in preferred range for employee |
|
Days worked in rolling window not in preferred range for employee |
|
Days worked per period not in preferred range for employee |
|
Employee assignment disrupted on replanning |
|
Employee does not have preferred daily shift pairing |
|
Employee has unpreferred daily shift pairing |
|
Employee has unpreferred shift near day off request |
|
Employee is paired with preferred employee |
|
Employee is paired with unpreferred employee |
|
Employee works compact sequence |
|
Employee works during preferred time |
|
Employee works during unpreferred time |
|
Employee works preferred multi day shift sequence pattern |
|
Employee works preferred single day shift sequence pattern |
|
Employee works shift with preferred shift tags |
|
Employee works unpreferred multi day shift sequence pattern |
|
Employee works unpreferred single day shift sequence pattern |
|
Locations worked per period not in preferred range for employee |
|
Minimize gaps between shifts for employee |
|
Minimize travel distance |
|
Minutes between shifts not in preferred range for employee |
|
Minutes logged per period not in preferred range for employee |
|
Minutes worked in rolling window not in preferred range for employee |
|
Minutes worked per period not in preferred range for employee |
|
Preferred employee assigned |
|
Preferred minimum time between different sequences not met for employee |
|
Preferred sequence start day met for employee |
|
Preferred shift rotation not met for employee |
|
Preferred skill missing |
|
Sequence ends on allowed sequence start day for employee |
|
Shift start time difference in minutes per period not in preferred range for employee |
|
Shift types worked per period not in preferred range for employee |
|
Shifts worked in rolling window not in preferred range for employee |
|
Shifts worked not in preferred hourly demand range |
|
Shifts worked per period not in preferred range |
|
Shifts worked per period not in preferred range for employee |
|
Unassigned optional shift |
|
Unique tags per period not in preferred limit |
|
Unpreferred employee assigned |
|
Weekend minutes worked per period not in preferred range for employee |
|
Weekends worked in rolling window not in preferred range for employee |
|
Weekends worked per period not in preferred range for employee |
|
Next
-
See the full API spec or try the online API.
-
Learn more about employee shift scheduling from our YouTube playlist.
-
Learn about balancing different optimization goals.