MinHoursRoster

MinHoursRoster(num_days, resources, shifts, ...)

Assigns named resources to required positions by day and shift.

MinHoursRoster.solve()

Runs the optimization solver

class pyworkforce.rostering.MinHoursRoster(num_days: int, resources: list, shifts: list, shifts_hours: list, min_working_hours: int, banned_shifts: list, max_resting: int, required_resources: list, non_sequential_shifts: list = None, resources_preferences: list = None, resources_prioritization: list = None, max_search_time: float = 240, num_search_workers=2)[source]

Assigns named resources to required positions by day and shift.

The solver supports restrictions such as banned shifts, non-sequential shifts, rest days, and minimum working hours. It also supports soft shift preferences. The objective is to minimize total scheduled hours, optionally weighted by resource shift preferences.

Parameters:
num_days: int,

Number of days to schedule.

resources: list[str],

Resources available to schedule.

shifts: list,

List of shift names.

shifts_hours: list,

Array of size [shifts] with the duration of each shift.

min_working_hours: int,

Minimum working hours per resource in the planning horizon.

banned_shifts: list[dict]

Each element has the form {"resource": resource_id, "shift": shift_name, "day": day_number} and marks a shift that the resource cannot work on that day. example: banned_shifts”: [{“resource”:”e.johnston@randatmail.com”, “shift”: “Night”, “day”: 0}],

max_resting: int,

Maximum number of resting days per resource in the planning horizon.

required_resources: dict[list]

Each key must be a shift name, and each value must be a list of length num_days with the required resources for that shift each day.

non_sequential_shifts: List[dict]

Each element must have the form {"origin": first_shift, "destination": second_shift} to prevent destination from being assigned the day after origin. example: [{“origin”:”Night”, “destination”:”Morning”}]

resources_preferences: list[dict]

Each element must have the form {"resource": resource_id, "shift": shift_name} and indicates that the resource prefers that shift.

resources_prioritization: list[dict], default=None

Each element must have the form {"resource": resource_id, "weight": weight} and represents the relative importance of that resource’s preferences.

max_search_time: float, default = 240

Maximum time, in seconds, to search for a solution.

num_search_workers: int, default = 2

Number of workers used to search for a solution.

solve()[source]

Runs the optimization solver

Returns:
solutiondict,

Dictionary that contains the status on the optimization, the list of resources to shift in each day and the list of resources resting for each day