Skip to content

Commit

Permalink
refactor(core): rename objectives to preferences
Browse files Browse the repository at this point in the history
The term "objective" clashes with the term "objective function" in optimization.
Refactored to follow the terminology used in the 2023/08/20 POC.
  • Loading branch information
j3soon committed Jul 26, 2024
1 parent f8f2907 commit 43faf1e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/nurse_scheduling/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def __init__(self) -> None:
self.enddate = None
self.requirements = None
self.people = None
self.objectives = None
self.preferences = None
self.dates = None
self.n_days = None
self.n_requirements = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def all_people_work_at_most_one_shift_per_day(ctx, args):
maximum_n_shifts = 1
ctx.model.Add(actual_n_shifts <= maximum_n_shifts)

OBJECTIVE_TYPES_TO_FUNC = {
PREFERENCE_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,
}
16 changes: 8 additions & 8 deletions core/nurse_scheduling/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ortools.sat.python import cp_model

from . import export, objective_types
from . import export, preference_types
from .context import Context
from .dataloader import load_data

Expand All @@ -20,7 +20,7 @@ def schedule(filepath: str, validate=True, deterministic=False):
enddate = scenario.enddate
requirements = scenario.requirements
people = scenario.people
objectives = scenario.objectives
preferences = scenario.preferences
del scenario
n_days = (enddate - startdate).days + 1
n_requirements = len(requirements)
Expand Down Expand Up @@ -68,12 +68,12 @@ def schedule(filepath: str, validate=True, deterministic=False):
for k in vars(ctx):
setattr(ctx, k, locals()[k])

logging.info("Adding objectives (i.e., preferences and constraints)...")
# TODO: Check no duplicated objectives
# TODO: Check no overlapping objectives
# TODO: Check all required objectives are present
for objective in objectives:
objective_types.OBJECTIVE_TYPES_TO_FUNC[objective.type](ctx, objective.args)
logging.info("Adding preferences (including constraints)...")
# TODO: Check no duplicated preferences
# TODO: Check no overlapping preferences
# TODO: Check all required preferences are present
for preference in preferences:
preference_types.PREFERENCE_TYPES_TO_FUNC[preference.type](ctx, preference.args)

logging.info("Initializing solver...")
solver = cp_model.CpSolver()
Expand Down
2 changes: 1 addition & 1 deletion core/tests/testcases/example_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ requirements:
- id: N
description: Night shift requirement
required_people: 1
objectives:
preferences:
- type: all requirements fulfilled
- type: all people work at most one shift per day

0 comments on commit 43faf1e

Please sign in to comment.