Skip to content

Feat/standard shift constraints #1618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dambry
Copy link

@dambry dambry commented May 28, 2025

No description provided.

This commit introduces a set of pre-built constraints and a corresponding
generic domain model for common shift scheduling use cases.

Key changes:

1.  **New Domain Model (`domain/shift_scheduling.py`):**
    *   Defined `Timeslot` (with overlap detection), `Skill`, `Employee` (with skills and unavailability), and `Shift` (with required skill and employee as planning variable).
    *   These classes are decorated with `@problem_fact` or `@planning_entity` as appropriate.

2.  **New Standard Constraints (`score/standard_shift_constraints.py`):**
    *   Implemented three common hard constraints:
        *   `no_overlapping_shifts`: Penalizes if an employee is assigned to two shifts that overlap in time.
        *   `employee_availability`: Penalizes if an employee is assigned to a shift during their unavailable times.
        *   `skill_requirement`: Penalizes if an employee assigned to a shift lacks the required skill.
    *   Created a constraint provider function `define_standard_shift_constraints` to bundle these constraints.

3.  **Unit Tests (`test/python/score/test_standard_shift_constraints.py`):**
    *   Added unit tests for each new constraint using `ConstraintVerifier`.
    *   Tests cover scenarios for both violations and adherence to the constraints.

4.  **Exposure in API:**
    *   Updated `domain/__init__.py` and `score/__init__.py` to make the new domain classes and constraint provider function easily importable by you when using the library.

These additions provide you with a foundational set of tools for building shift scheduling solutions with Timefold Solver, reducing boilerplate and demonstrating best practices.
This commit extends the standard shift scheduling constraints with two new
hard constraints based on your feedback:

1.  **Domain Model Updates (`domain/shift_scheduling.py`):**
    *   The `Employee` class now includes:
        *   `cannot_work_with: list[str]`: Stores IDs of employees this employee cannot have overlapping shifts with.
        *   `classification: str`: For roles like "nurse", "paramedic".
        *   `is_senior: bool`: Indicates seniority, relevant for certain roles.

2.  **New 'Cannot Work Together' Constraint (`score/standard_shift_constraints.py`):**
    *   Penalizes if two employees who are specified in each other's `cannot_work_with` lists are assigned to overlapping shifts.

3.  **New 'Seniority Requirement' Constraint (`score/standard_shift_constraints.py`):**
    *   Penalizes a shift staffed by a junior ("is_senior=False") nurse or paramedic if no other nurse or paramedic (junior or senior) is working in any concurrently overlapping shift. This ensures a lone nurse/paramedic has seniority.

4.  **Unit Tests (`test/python/score/test_standard_shift_constraints.py`):**
    *   Added comprehensive unit tests for both new constraints, covering various scenarios of violation and satisfaction.
    *   A helper function `_create_test_employee` was added to streamline test setup.

5.  **Constraint Provider Update:**
    *   Both new constraints have been added to the `define_standard_shift_constraints` provider function.

These additions further enhance the pre-built capabilities for shift scheduling solutions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant