or-tools employee scheduling based on workload

121 Views Asked by At

Below, only one worker (w) can work each day (d). I want to schedule workers based on their workload/jobs remaining. The current solution will schedule worker 1 or 3 each day as they have the largest workload. Assuming that each day worked will result in a workload reducing by 2, I want to incorporate this. This should result in workers 1 and 3 working two days (workload: 6 > 4 > 2) and worker 2 working one day (5 > 3). I tried to reduce the "jobs_remaining" variable by 2 if "Worked", but it won't work like this.

I'm wondering if possible to achieve this in... (A) any particular order, and (B) ordered based on jobs remaining by day: Day 1 = worker 1 or 3 (6 remaining), Day 2 = worker 1 or 3 (6 remaining), Day 3 = worker 2 (5 remaining), Day 5 = worker 1 or 3 (4 remaining)

days = [1,2,3,4,5]
workers = [1,2,3,4]
jobs_to_do_by_worker = [6,5,6,2]

worked_array = [] 
for w, jobs_remaining in zip(workers,jobs_to_do_by_worker):
    for d in days:
        worked = model.NewBoolVar('name')
        model.Add(allocations[(w,d)] == 1).OnlyEnforceIf(worked)
        model.Add(allocations[(w,d)] != 1).OnlyEnforceIf(worked.Not())
        worked_array.append(worked * jobs_remaining)
        
        #### jobs_remaining = jobs_remaining-(worked * 2) ####
              
model.Maximize(sum(worked_array))

1

There are 1 best solutions below

2
On

So each day you want to pick an index whose value is a max in the jobs_to_do_by_worker array, remove two, then repeat ?