-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
66 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Context: | ||
def __init__(self) -> None: | ||
self.startdate = None | ||
self.enddate = None | ||
self.requirements = None | ||
self.people = None | ||
self.objectives = None | ||
self.dates = None | ||
self.n_days = None | ||
self.n_requirements = None | ||
self.n_people = None | ||
self.model = None | ||
self.shifts = None | ||
self.map_dr_p = None | ||
self.map_dp_r = None | ||
self.map_d_rp = None | ||
self.map_r_dp = None | ||
self.map_p_dr = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from . import utils | ||
|
||
def all_requirements_fulfilled(ctx, args): | ||
# Hard constraint | ||
# For all shifts, the requirements (# of people) must be fulfilled. | ||
# Note that a shift is represented as (d, r) | ||
# i.e., sum_{p}(shifts[(d, r, p)]) == required_n_people, for all (d, r) | ||
for (d, r), ps in ctx.map_dr_p.items(): | ||
actual_n_people = sum(ctx.shifts[(d, r, p)] for p in ps) | ||
required_n_people = utils.required_n_people(ctx.requirements[r]) | ||
ctx.model.Add(actual_n_people == required_n_people) | ||
|
||
def all_people_work_at_most_one_shift_per_day(ctx, args): | ||
# Hard constraint | ||
# For all people, for all days, only work at most one shift. | ||
# Note that a shift in day `d` can be represented as `r` instead of (d, r). | ||
# i.e., sum_{r}(shifts[(d, r, p)]) <= 1, for all (d, p) | ||
for (d, p), rs in ctx.map_dp_r.items(): | ||
actual_n_shifts = sum(ctx.shifts[(d, r, p)] for r in rs) | ||
maximum_n_shifts = 1 | ||
ctx.model.Add(actual_n_shifts <= maximum_n_shifts) | ||
|
||
OBJECTIVE_TYPES_TO_FUNC = { | ||
"all requirements fulfilled": all_requirements_fulfilled, | ||
"all people work at most one shift per day": all_people_work_at_most_one_shift_per_day, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters