Stuck on how to add constraint in Scheduling problem :Python

107 views
Skip to first unread message

ตะวัน บุญธนภัทร

unread,
Mar 6, 2019, 12:38:11 PM3/6/19
to or-tools-discuss
I’m working on the Nurse Scheduling Problem
I modified many constraint to suit my situation.
Until i currently stuck on how to Add constraint
That in every employee must have at least
once of 2-“consecutive” days of Day-OFF.

My situation
Number of days = 7
Number of employees = 7
Number of shifts per day = 4

Each employee has 3 days OFF in a week
But i want at least once that the day OFF is next to each other.

I didn’t include OFF as a shift
so for my code the sum of every shift in one day is 0 mean day OFF.

I tried to make a list of work of every employee
to be [d1,d2,d3...d7] -> [1,0,1,...0]
If 1 mean that employee work on day 1 and
0 mean they off on that day
By this code:
For employee in all_employee:
work_day = []
For d in all_days
work_day.append(sum(shift[(d,s,employee)] for s in all_shifts))

Then I make a new list of consecutive day
[(d1+d2),(d2+d3),(d3+d4)....(d6+d7)]
By
consecutive_day = []
for i in range(num_day - 1)
consecutive_day.append(work_day[i] + work_day[i+1], ... )

Then 0 should indicate the 2-days OFF in consecutive
So I add constraint
model.AddBoolOr([0 in consecutive_day])
But this doesn’t work
I don’t understand

I tried more than several approaches but none works
....
Could you please suggest on how to do this please.
Thank you.







Laurent Perron

unread,
Mar 6, 2019, 2:26:14 PM3/6/19
to or-tools-discuss
AddBoolOr takes an array of boolean variables, or their negation.

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages