API Reference
Auto-generated reference for the shiftcraft_core package. All public symbols are documented here from their source docstrings.
Entry point
Main entry point: solve the scheduling problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
Raw JSON dict containing period, team, coverage, and holidays. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with solution status, schedule, summary, and penalty (or conflicts). |
Model building
Build the complete CP-SAT model with variables, constraints, and objective.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inp
|
ScheduleInput
|
The parsed schedule input. |
required |
Returns:
| Type | Description |
|---|---|
CpModel
|
Tuple of (model, vars_dict) where vars_dict contains all decision variables |
dict[str, Any]
|
and metadata needed for solution formatting. |
Input parsing
Parse and validate input JSON payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
Raw JSON dict containing period, team, coverage, and holidays. |
required |
Returns:
| Type | Description |
|---|---|
ScheduleInput
|
Validated ScheduleInput with all dates expanded and structures parsed. |
Data types
Complete input specification for schedule generation.
get_coverage(d)
Return effective coverage for a date.
Applies date-range overrides first, falls back to day-of-week defaults.
is_holiday_for(d, city)
Check if a date is a holiday for a specific city.
Override default coverage for a specific date range.
covers(d)
Check if this override applies to the given date.
get_slot(shift)
Get the coverage slot for a specific shift.
Variables
Create all decision variables for the scheduling problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
CpModel
|
The CP-SAT model to add variables to. |
required |
inp
|
ScheduleInput
|
The parsed schedule input. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Constraints
Add all hard constraints to the CP-SAT model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
CpModel
|
The CP-SAT model to add constraints to. |
required |
inp
|
ScheduleInput
|
The parsed schedule input. |
required |
vars_dict
|
dict[str, Any]
|
Dictionary containing decision variables and metadata. |
required |
Objective
Formatter
Build the output dict from solver results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
CpSolverStatus
|
CP-SAT solver status code. |
required |
solver
|
CpSolver
|
The CP-SAT solver instance. |
required |
inp
|
ScheduleInput
|
The parsed schedule input. |
required |
vars_dict
|
dict[str, Any]
|
Dictionary containing decision variables and metadata. |
required |
conflict_reasons
|
list[str] | None
|
Optional list of conflict explanations for infeasible solutions. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
On failure: {"status": "infeasible", "conflicts": [...]} |
dict[str, Any]
|
On success:
{
"status": "ok" | "feasible",
"schedule": [{"date": ..., " |
Diagnostics
Analyze input to identify potential causes of infeasibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inp
|
ScheduleInput
|
The parsed schedule input. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of human-readable conflict explanations. |