API — Breaks
pyworkforce.breaks
BreakScheduler
python
BreakScheduler(
num_days,
periods,
shifts_coverage,
scheduled_resources,
breaks,
min_coverage,
max_search_time=120.0,
num_search_workers=2,
)Schedules breaks for agent slots within each shift to maintain minimum coverage throughout the planning horizon. Each shift/day combination has scheduled_resources[shift][day] anonymous agent slots; the solver assigns a start period to every break for every slot while enforcing break windows, non-overlap, and coverage constraints.
Parameters
- num_days (
int) — number of days in the planning horizon. - periods (
int) — number of periods per day (e.g.48for 30-minute slots in a 24-hour day). - shifts_coverage (
dict) —{"shift_name": coverage_array}wherecoverage_arrayhas lengthperiodsand uses1when the shift is active,0otherwise. - scheduled_resources (
dict) —{"shift_name": [count_day0, count_day1, …]}with the number of agent slots per shift per day (typically the output of the scheduling step). - breaks (
list[dict]) — break definitions. Each dict must have:name(str) — unique identifier.duration_periods(int) — break length in periods.min_start_after(int, default0) — periods into the shift before the break may start.max_end_before(int, default0) — periods remaining in the shift after the break must finish.
- min_coverage (
list) — 2-D array[num_days][periods]— minimum agents that must remain available (not on break) at each period. - max_search_time (
float, default120.0) — maximum solver wall-clock time in seconds. - num_search_workers (
int, default2) — number of parallel search workers.
Attributes
- solution_ (
dictorNone) — the last result returned bysolve(), orNoneifsolve()has not been called.
Methods
solve()→dictRun the CP-SAT solver and return a result dict with:
status(str) —"OPTIMAL","FEASIBLE", or"INFEASIBLE".cost(float) — objective value (0.0for optimal/feasible;-1when infeasible).break_schedule(list[dict]) — one entry per(shift, day, slot, break). Each entry containsshift,day,slot,break_name,start_period(inclusive) andend_period(exclusive).
get_params()→dict
See the Break scheduling guide.