Skip to content

Commit

Permalink
Match documented constraint priority
Browse files Browse the repository at this point in the history
Swapped the soon enough and late enough constraints in code, since even distribution should be higher priority than spacing
  • Loading branch information
willowv committed Jun 19, 2021
1 parent 1d14f66 commit 357b5fe
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions calculateShifts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 357b5fe

Please sign in to comment.