1. Introduction
In labor-intensive and highly regulated industries such as healthcare, aviation, customer service, and manufacturing, shift scheduling has long been a crucial issue in human resource allocation [
1]. These industries must ensure adequate staffing to maintain daily operations and strictly comply with complex labor laws and industry-specific regulations concerning working hours, rest periods, and professional certifications. However, traditional scheduling practices often rely heavily on manual experience or partially automated tools, which easily lead to scheduling flaws. Common problems include violations of legal regulations (such as excessive working hours or insufficient rest intervals), complaints from employees about unfair or overly demanding schedules, and overall inefficiency in workforce utilization. These issues not only lower staff morale and satisfaction but may also pose potential legal risks and negatively impact service quality and operational productivity.
Approaches have been proposed to solve the shift scheduling problem, each of which has its own limitations. Traditional operations research methods, such as integer programming [
2], can provide exact solutions but require excessive computation time for large-scale problems and typically depend on expensive commercial solvers such as IBM ILOG CPLEX Optimization Studio (CPLEX) [
3] or Gurobi Optimizer [
4]. Metaheuristic algorithms, such as the genetic algorithm (GA) [
5], can handle larger problem sizes but suffer from difficulties in parameter tuning, an inability to guarantee full constraint satisfaction, and unstable solution quality. Some studies have explored the use of deep learning methods such as reinforcement learning and graph neural networks [
6] to solve the shift scheduling problem. However, these approaches often require large amounts of training data, lack interpretability, and involve high implementation complexity, making them unsuitable for widespread adoption.
Recently, Google has introduced OR-Tools [
7], an open-source optimization suite that integrates multiple solving paradigms, including linear programming (LP), integer programming (IL), mixed-integer programming (MIP), constraint programming (CP), and constraint programming with satisfiability (CP-SAT) [
8]. It provides a unified framework for modeling and solving complex combinatorial optimization problems (COPs). Specifically, OR-Tools models a COP in Python 3.10 by defining variables, constraints, and an objective function (OF), invokes a solver to optimize the OF, and returns solution(s) to the COP. OR-Tools has been widely applied in many critical domains, including complex nurse rostering or nurse scheduling in healthcare institutions to ensure sufficient staffing while complying with all professional and regulatory requirements [
9].
We applied the OR-Tools CP-SAT solver to the nurse scheduling problem (NSP) in hospitals. Nurse scheduling must simultaneously satisfy multiple complex constraints, which can generally be categorized into two types: hard constraints and soft constraints. Hard constraints must never be violated, whereas soft constraints should be satisfied as much as possible. As will be shown later, CP-SAT can handle the two types of constraints properly. This paper also conducts experiments and takes GA as a baseline method to perform a comparative analysis between GA and CP-SAT.
The remainder of this article is organized as follows.
Section 2 presents the mathematical formulation of the NSP.
Section 3 describes several modeling techniques to facilitate the formulation using CP-SAT.
Section 4 reports and discusses the experimental results of CP-SAT and GA. Finally,
Section 5 concludes the paper.
2. Problem Formulation
NSP is solved to assign an appropriate shift to each nurse for each day so that all hard constraints are satisfied while soft constraints are optimized as much as possible. The following illustrates how to formulate an NSP instance by defining nurses, shifts, days, variables, constraints, and the objective function. NSP is defined given a set of nurses, a scheduling period, types of shifts, and hard and soft constraints:
Nurses: Let be the set of nurses.
Shifts: Let be the set of possible shifts. There are four types of shifts: D (for day shift) from 08:00 to 16:00, E (for evening shift) from 16:00 to 24:00, N (for night shift) from 00:00 to 08:00, and OFF (for day OFF).
Days: Let be the set of days.
Decision variables: Let be a binary decision variable indicating whether nurse i on day d is assigned to shift s (including the day off, OFF). If nurse i on day d is assigned to shift s, then = 1; otherwise, = 0.
Hard constraints (HCs): All hard constraints must be strictly satisfied. Below is an example of hard constraints: . It is to ensure that each nurse is assigned to exactly one shift per day. Moreover, below is another example of hard constraints: + + ≤ 2, . This constraint prevents the occurrence of the N–OFF–D shift pattern within any three consecutive days for each nurse.
Virtual nurses or virtual staff members: Let be the set of virtual nurses or virtual staff members. The concept of virtual staff is to increase scheduling flexibility and handle potential staff shortages. Virtual staff are treated as temporary personnel who can be assigned shifts when the available workforce is insufficient. During scheduling, they are prioritized for days off and are only assigned to work shifts when necessary to meet minimum staffing requirements.
Soft constraints (SCs): Soft constraints represent desirable but non-mandatory conditions that aim to improve schedule quality, fairness, and staff satisfaction, and are incorporated into the objective function as penalty terms to be minimized. For example, to ensure that virtual nurses (temporary or substitute staff) are only assigned when necessary, a penalty is applied whenever a virtual nurse is scheduled to work instead of being off duty. This encourages the solver to allocate off days to virtual staff whenever sufficient regular nurses are available. We thus have a soft constraint: , where is the penalty coefficient applied when a virtual nurse is not scheduled for a day off. Below is another example of soft constraints: , where is the penalty coefficient applied when the workload of a nurse deviates from the target workload, is the workload of nurse i and is the target working hours (e.g., 160 h per four weeks).
Objective function: The objective function aims to minimize the total penalty incurred from violating soft constraints while ensuring that all hard constraints are fully satisfied. Each soft constraint contributes a penalty term weighted by its corresponding coefficient, reflecting its relative importance in the optimization process. For example, below is an example of the objective function:
3. Methodology
This section introduces several modeling techniques and strategies that facilitate the formulation and implementation of the NSP using the CP-SAT solver. The modeling techniques are described below:
Boolean composition is used to represent abstract scheduling semantics, such as prohibiting a day shift immediately after a night shift. To define such violations, auxiliary Boolean variables are introduced:
Let denote that nurse i on day d works a night shift (N), and let denote that the same nurse on day d + 1 works a day shift (D).
A violation flag variable can then be constructed by using logical AND composition: = AND (), where indicates that nurse i is assigned a night shift followed by a day shift on a consecutive day. To prevent such a pattern, the following constraint is imposed: = 0.
The advantage of Boolean composition is that these auxiliary violation variables can be flexibly reused and combined with other logical conditions. For instance, the same violation marker can be extended to capture special situations such as = 1 and (indicating that day d is a holiday), thereby triggering additional rules or penalties. This modular design enables the model to encapsulate high-level semantics as logical components, facilitating flexible rule construction, extension, and maintenance.
Certain real-world scheduling goals, such as maintaining total working hours close to a target value, are better represented as optimization objectives rather than hard constraints. For example, we transform the “the closer, the better” relationship into an optimization objective by minimizing the absolute deviation through AddAbsEquality linearization: , where stands for the working hours (duration) of shift s, for example, 8 h for the day shift, 8 h for the evening shift, and 10 h for the night shift.
This soft approximation represents the minimization of deviation from 160 total working hours. It allows CP-SAT to minimize deviations and produce balanced schedules.
To represent whether a nurse has been assigned to any shift during the scheduling period, we define the following binary variable: , where is a binary assignment variable, and denotes the set of all possible day–shift combinations. If nurse i has been assigned to at least one shift s on any day d, then ; otherwise, . This variable allows the model to distinguish between nurses who are actually scheduled and those who are not activated during the scheduling period.
Based on this definition, two types of cost structures are introduced.
- 1.
Fixed cost: This represents a one-time cost incurred when a nurse is activated at least once, for example, an attendance bonus, activation fee, or contractual subsidy. The cost can be expressed as meaning that the cost is charged once whenever .
- 2.
Marginal cost: This cost accumulates with the actual number of assigned shifts, such as daily wages, overtime pay, or fatigue cost. It can be formulated as indicating that a cost is incurred each time a shift assignment occurs.
The variable captures the activation state of each nurse, enabling the model to account for both one-time activation costs and cumulative workload-based costs within the same optimization framework.
Daily staffing requirements are dynamically modeled to reflect both baseline and adjustable demand levels. The minimum staffing demand is dynamically generated as , which combines two components: a fixed baseline requirement for each shift type s, and a dynamic adjustment term that accounts for day-of-week variations (e.g., higher demand on Mondays or lower demand on weekends). This formulation allows the model to reflect both long-term average staffing needs and short-term fluctuations in daily workload.
For each day d and shift type s, the following constraint is imposed to ensure sufficient staffing: , where denotes the required number of staff for shift s on day d. Similar constraints can be used to ensure that the required number of senior or qualified nurses is also satisfied.
4. Results and Discussion
We used an NSP instance to solve it with the CP-SAT solver to verify the correctness of its solutions. We also take GA as a baseline and use it to solve the same instance. The GA results are compared with those of CP-SAT to evaluate the solver’s performance. Below, the problem instance is first described. We then present the experimental CP-SAT and GA results, followed by a detailed analysis and comparison of the results.
Due to space limitations, we present a simple NSP instance in this study. The instance is solved by both CP-SAT and GA. The instance contains four components: employee information, daily staffing requirements, shift types, and constraints (or rules or regulations). For simplicity, all constraints are defined within a single month (i.e., no cross-month constraints), and the activation costs are not considered.
Staff: Ten regular nurses (B00001–B00010) and three virtual nurses (V001–V003).
Default shift assignments:
- −
Day shift (D): 4 nurses—B00003, B00005, B00007, B00008.
- −
Evening shift (E): 3 nurses—B00002, B00004, B00010.
- −
Night shift (N): 3 nurses—B00001, B00006, B00009.
- −
Three virtual nurses are assigned OFF shifts by priority.
Public regulation:
- −
LAW01: Total working hours within four weeks ≤ 160 h (SC).
- −
LAW02: At least two rest days are required within every two-week period (HC).
- −
LAW03: Maximum of 12 consecutive working days per month (HC).
- −
LAW04: Minimum rest interval between two shifts ≥ 11 h (HC).
Staffing requirements (HC):
- −
Day shift (D): ≥3 nurses; evening shift (E): ≥2 nurses; night shift (N): 2 nurses
IN01: No “N–OFF–D” pattern in any 3-day window (HC).
IN02: Weekend off days should be evenly distributed among nurses (SC).
IN03: Align with last year’s schedule pattern wherever practicable (SC).
We use CP-SAT to solve the problem instance. The solution is shown in
Figure 1. We have checked the solution to verify that all hard constraints are strictly satisfied. Thus, the solution is in practice a feasible solution.
We used GA as the baseline to solve the same problem instance. GA is a population-based metaheuristic inspired by natural selection. It represents a candidate schedule as a chromosome and iteratively improves a population of such chromosomes through selection, crossover, and mutation. A fitness function evaluates each schedule by penalizing constraint violations, guiding the search toward high-quality solutions. Owing to its stochastic exploration–exploitation balance and independence from gradient information, GA is well-suited to COPs such as nurse scheduling, though it does not guarantee global optimality or feasibility.
The GA parameter settings are as follows: population size = 10,000, generations = 500, crossover rate = 0.4, mutation rate = 0.3, soft constraint penalty = 10, and hard constraint penalty = 10,000,000. The initial population is randomly generated by assigning one of the four shift types (D, E, N, and OFF) to each nurse for every day in the scheduling period.
During the evolutionary process, each chromosome represents a complete nurse schedule. The fitness function evaluates the quality of each chromosome by penalizing violations of hard and soft constraints, ensuring that feasible and high-quality schedules are favored across generations. The two-point crossover operation is used for the recombination of chromosomes. In the operation, two parent chromosomes are randomly selected, and two crossover points a and b are chosen within the data range. Segments between these points are exchanged to create offspring. This design allows advantageous schedule segments (partial feasible solutions) from different parents to be combined, increasing the chance of producing better solutions.
Mutation introduces diversity by randomly altering genes in offspring. In our experiment, with an 80% probability, the algorithm performs a swap mutation: it randomly selects a nurse i and two dates a and b, then exchanges the assigned shifts of that nurse between days a and b. With the remaining 20% probability, a single-point mutation is performed: a nurse i and a date d are randomly selected, and the assigned shift of nurse i on day d is replaced with another randomly chosen shift type. This mixed mutation strategy balances exploration (searching new areas) and exploitation (refining promising schedules).
Through 500 successive generations, GA evolves toward solutions that satisfy hard constraints and minimize soft-constraint penalties, and returns the best ever solution as the ultimate nurse schedule. Through the experimental results shown in
Figure 2, we observe that GA shows no clear convergence in fitness values and often yields infeasible schedules (violating hard constraints). Under identical hardware and the same NSP instance, GA took 109.08 s, while CP-SAT solved it in 0.446 s; CP-SAT is about 224.6 times faster than GA. All in all, CP-SAT consistently produces feasible solutions, indicating superior efficiency and applicability for solving the NSP.
5. Conclusions
In this study, we demonstrate the effectiveness of Google OR-Tools CP-SAT in solving NSP with multiple complex constraints. We benchmark CP-SAT against GA with a simple NSP instance and, beyond benchmarking, contribute a clear problem formulation and a set of modeling techniques that make complex rules tractable in practice. Experimental results show that CP-SAT consistently produces feasible, balanced schedules that satisfy all hard constraints while substantially reducing computation time relative to GA. Overall, CP-SAT offers a practical, scalable, and reliable framework for nurse scheduling, with applicability to broader workforce planning settings. We applied CP-SAT to a real large-scale hospital NSP and obtained a fully feasible schedule. Further study is required to extend the formulation to incorporate uncertainty-aware demand and investigate multi-objective trade-offs (e.g., fairness–stability, coverage–preference, and cost–quality) as well as learning-augmented forecasts to further enhance robustness and usability.