Docs
  • Solver
  • Models
    • Field Service Routing
    • Employee Shift Scheduling
    • Pick-up and Delivery Routing
    • Task Scheduling
  • Platform
Start Free Trial
  • Employee Shift Scheduling
  • Lessons overview
  • Lesson 1
  • latest
    • latest
    • 1.35.x
    • 1.34.x

Employee Shift Scheduling

    • Introduction
    • Getting started: Hello world
    • Lessons overview
      • Lesson 1
      • Lesson 2
      • Lesson 3
      • Lesson 4
      • Interlude 1: Basic demo data
    • User guide
      • Terminology
      • Use case guide
      • Scheduling API concepts
      • Integration
      • Constraints
      • Using the API
        • Using the OpenAPI spec
        • API tooling
      • Demo datasets
      • Input datasets
        • Model configuration
        • Model input
        • Planning window
      • Planning window
      • Time zones and Daylight Saving Time (DST)
      • Tags and tag types
      • Input validation
      • Output datasets
        • Metadata
        • Model output
        • Input metrics
        • Key performance indicators (KPIs)
      • Metrics and optimization goals
      • Score analysis
      • Visualization
      • Efficiency X-Ray
      • Assignability analysis
    • Employee resource constraints
      • Employee availability and preferences
        • Employee availability
        • Employee preferences
      • Employee contracts
      • Employee priority
      • Pairing employees
      • Employee groups
      • Shift travel and locations
      • Shift Breaks
      • Employee activation
      • Work limits
        • Minutes worked per period
        • Minutes worked in a rolling window
        • Minutes logged per period
        • Days worked per period
        • Days worked in a rolling window
        • Consecutive days worked
        • Shifts worked per period
        • Shifts worked in a rolling window
        • Weekend minutes worked per period
        • Weekends worked per period
        • Weekends worked in a rolling window
        • Consecutive weekends worked
        • Consecutive shifts worked
      • Time off
        • Days off per period
        • Consecutive days off per period
        • Consecutive days off in a rolling window
        • Consecutive minutes off in a rolling window
        • Shifts to avoid close to day off requests
        • Consecutive weekends off per period
      • Shift rotations and patterns
        • Shift rotations
        • Single day shift sequence patterns
        • Minimize gaps between shifts
        • Multi-day shift sequence patterns
        • Daily shift pairings
        • Overlapping shifts
        • Shift start times differences
        • Minutes between shifts
      • Shift type diversity
        • Shift tag types
        • Shift types worked per period
        • Unique tags per period
      • Fairness
        • Balance time worked
        • Balance shift count
    • Shift service constraints
      • Alternative shifts
      • Cost management
        • Cost groups
        • Employee rates
      • Demand-based scheduling
      • Priority and optional shifts
      • Skills and risk factors
      • Shift assignments
        • Shift selection
        • Employee selection
    • Manual intervention
    • Recommendations
    • Real-time planning
    • Scenarios
      • Configuring labor law compliance
      • Configuring employee well-being
      • Self-rostering and optimization
    • Changelog
    • Upgrade to the latest version
    • Feature requests

Lesson 1: Thinking about constraints

Introduction

Constraints are the rules that govern the assignment of shifts to employees. Over the course of this lesson series, you will learn how to think about converting scheduling rules into Timefold constraints.

Think of a person whose job it is to create employee schedules. Let’s call them "a planner". When assigning shifts to employees, a planner must think of all the rules that the shifts must follow in order for the schedule to be valid. For example, a planner might consider the following:

  • How many hours each employee can work in a day or week.

  • Whether any employees must work with a supervisor or manager on certain shifts.

  • How much rest employees must have between shifts.

  • How many night shifts employees can work in a row.

  • What department each employee prefers to work in.

  • Any unavailability that employees might have, such as vacation time.

All of these rules, and many more, are referred to as constraints in a Timefold schedule. Most constraints must be activated by including the related JSON in the input dataset. The Timefold model considers all activated constraints for all employees at once when assigning shifts in a schedule.

It is a good idea to compile a list of all the rules that apply to the schedule in advance. Gaining a deep understanding of the problem is very valuable before trying to convert the rules into Timefold constraints.

The constraints are split into categories based on the type of rule they represent.

The schedule has an overall score which represents how well the activated constraints are satisfied. The score is split into three parts: hard, medium, and soft. For example, -167hard/-3medium/10673soft.

Hard constraints

Hard constraints are rules that cannot be broken. There are many reasons why this could be the case. Perhaps the rule is a legal requirement, or perhaps it is a company policy. Regardless of the reason, hard constraints are rules that must be followed in order for a schedule to be valid.

The sum total of the contribution of all the hard constraints is referred to as the "hard score" of the schedule, for example -167hard. A hard score is never positive, since all hard score contributions are undesirable.

It is not possible to adjust the weight of the contribution of a hard constraint to the hard score. If any hard constraint is violated by any amount, the schedule is considered invalid. The Timefold model will never assign a shift that breaks a hard constraint by any amount, so it does not matter if that amount is -1 or -1000.

It is, however, possible to have schedules which have a negative hard constraint score. This can only happen in the case where shifts have been pre-assigned to employees in the input dataset, and they have been "pinned" in place so that the Timefold model cannot move them, and those assignments violate hard constraints. In this case, since the Timefold model cannot move the offending shifts, there will be a hard score in the final schedule.

If the offending shifts are not pinned in place, then the Timefold model will attempt to improve the hard score as much as possible by un-assigning or moving them. The Timefold model will never assign, or keep assigned, a shift that breaks a hard constraint by any amount.

The hard score should only ever stay the same or improve. It should never get worse. If you ever see a hard score in the output of a schedule that is worse than the initial hard score, contact [email protected] with the details of the dataset where this happened.

Soft constraints

Soft constraints are preferences, which can be broken. If a soft constraint is violated, the schedule is still valid. However, these types of constraints can be important for employee retention and reducing the business overhead to hire and train new employees. The Timefold model will try its best to satisfy as many soft constraints as possible, but it is not guaranteed to do so.

The sum total of the contribution of all the soft constraints is referred to as the "soft score" of the schedule, for example 10673soft.

It is possible to adjust the weight that a soft constraint contributes to the soft score. For example, it could be that an employee would prefer to work no more than 25 hours per week, but they love to work in a certain department and will take more hours there if they are available. Therefore, the employee’s preference for working in department A is more important than their preference for working 25 hours. In this case, the weight of the soft constraint for working in department A should be set higher than the weight of the soft constraint for working no more than 25 hours per week.

A later lesson will discuss how to adjust the weights of soft constraints, and how to balance them against each other, in more detail.

It is possible for a soft score to be positive. Some soft constraints penalize undesirable behavior, such as working in a department that an employee does not like. This constraint will contribute a negative (undesirable) amount to the soft score if the employee works a shift in that department. Other soft constraints reward desirable behavior, such as working with a supervisor that an employee prefers. This constraint will contribute a positive (desirable) amount to the score if the employee works at the same time as that supervisor. If the schedule satisfies more desirable behavior than undesirable behavior, the soft score will be positive.

Do not think of hard vs soft as different prioritization levels for constraints. The two types of constraints are not comparable. They are fundamentally treated differently by the Timefold model. Instead, think of whether or not the rule is flexible. If it is flexible, it is a soft constraint. If it is not flexible, it is a hard constraint.

Medium constraints

There is only one medium constraint active at any one time. By default, this constraint tells the Timefold model to assign as many mandatory shifts as possible. Unlike employee-specific constraints such as limits to working hours, the constraint to assign as many mandatory shifts as possible is always on by default and does not need any special configuration.

It is also possible to override the default behavior of assigning all shifts, and instead assign shifts to follow a demand curve. This is a more advanced topic and will be covered in a later lesson. You can read more about assigning shifts to a demand curve in the Demand-based scheduling technical documentation.

There is only one medium constraint active at any one time. Its total is referred to as the "medium score" of the schedule, for example -3medium.

Medium constraints are treated individually in their own level, because they are less important than hard constraints but more important than soft constraints.

Think of a planner assigning shifts to employees manually. They will never assign shifts which break legal limits or rules, but they will assign shifts which break preferences because sometimes it is necessary to fill all the mandatory shifts. The medium constraint is treated in the same way by the Timefold model. It will try to assign as many mandatory shifts as possible at the expense of preferences, but it will not do so at the expense of violating hard constraints.

By default, each mandatory shift in the input dataset which remains unassigned contributes -1 to the total medium score. As in the case of the hard and soft constraints, a negative contribution is undesirable (we do not want unassigned shifts in the dataset if possible). It is possible to rank shifts by priority and make them contribute different amounts to the medium score when they are unassigned. This will be covered in a later lesson.

Conclusion

In this lesson, we have learned about:

  • Different types of constraints in Timefold’s Employee Shift Scheduling model.

  • The conceptual differences between hard and soft constraints.

  • Hard, medium, and soft scores of a schedule.

  • Negative and positive contributions to the score of a schedule.

  • The importance of understanding the problem before trying to convert rules into Timefold constraints.

Next

  • Proceed to Lesson 2 to learn about configuring a simple constraint: skill requirements for shifts.

  • Discover more in-depth technical details about constraints in the Constraints documentation of the user guide.

  • Alternatively, go back to the Lessons overview to choose a different lesson to continue with.

  • © 2026 Timefold BV
  • Timefold.ai
  • Documentation
  • Changelog
  • Send feedback
  • Privacy
  • Legal
    • Light mode
    • Dark mode
    • System default