From 357b5feffbf478c631de8f46cf35523a34bb794b Mon Sep 17 00:00:00 2001 From: "Willow Vaughan (they/them)" Date: Sat, 19 Jun 2021 10:11:26 -0700 Subject: [PATCH] Match documented constraint priority Swapped the soon enough and late enough constraints in code, since even distribution should be higher priority than spacing --- calculateShifts.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/calculateShifts.py b/calculateShifts.py index 06e1e1a..462d1b0 100644 --- a/calculateShifts.py +++ b/calculateShifts.py @@ -106,25 +106,25 @@ def availableShift(shift): entity.done = True continue - # What shifts are far enough from the last shift this entity had? - def lateEnoughShift(shift): - return entity.lastShift == None or shift.date - entity.lastShift > numDaysBetweenShifts + # What shifts are soon enough to make sure that the shift counts are roughly equal overall? + def soonEnoughShift(shift): + comparisonDate = dateStart + if not entity.lastShift == None: + comparisonDate = entity.lastShift - shiftCandidatesB = list(filter(lateEnoughShift, shiftCandidatesC)) + return shift.date - comparisonDate < timeWindow + + shiftCandidatesB = list(filter(soonEnoughShift, shiftCandidatesC)) if len(shiftCandidatesB) == 0: # if there's no candidates in B, use C shiftCandidates = shiftCandidatesC entity.numCompromises += 2 else: - # What shifts are soon enough to make sure that the shift counts are roughly equal overall? - def soonEnoughShift(shift): - comparisonDate = dateStart - if not entity.lastShift == None: - comparisonDate = entity.lastShift - - return shift.date - comparisonDate < timeWindow + # What shifts are far enough from the last shift this entity had? + def lateEnoughShift(shift): + return entity.lastShift == None or shift.date - entity.lastShift > numDaysBetweenShifts - shiftCandidatesA = list(filter(soonEnoughShift, shiftCandidatesB)) + shiftCandidatesA = list(filter(lateEnoughShift, shiftCandidatesB)) if len(shiftCandidatesA) == 0: # if there's no candidates in A, use B shiftCandidates = shiftCandidatesB