So, I'm modelling a job assigning problem in OR-Tools CP-SAT. I want to maximize rescheduled jobs based on some constraints. Right now jobs in my model look like this:
jobs = [(1, 1, 1, 3, 1), # job id, job type, start time, length, worker id
...
(7, 5, 9, 1, 4)]
And the way I initialize data looks like this:
for h in range(horizon):
...
for w in workers:
...
for jt in job_types:
...
for job in jobs:
The data on top level is stored in smth like:
List<List<List<List<IntervalVar>>>> intervals_by_hour
Based on all of this I find it pretty hard already to initialize everything and select some of the data ranges to make constraints. Next, I would like to widen a job definition a bit, so I feel that I'll have another layer of for loops and a hard time isolating entities from them.
So the question is: Am I doing something wrong or is it some acceptable way of doing so? I've looked through examples and some books, and rn I dont feel neither those examples fit my needs well, nor some of them feel better in modeling part
Initial task: I get some jobs from the ERP system that (in this example) can overlap each other by the workers attached to them. (E.g. Alex can be assigned to job1 and job2 at the same time), so I want to reschedule such jobs. Every job consists of job ID, job type, start time, length, worker id. Right now in my model I use BoolVars to indicate that job exists and OptionalIntervals for a job to exist if BoolVar exists. Basically I want jobs of one type to not overlap, jobs of one worker to not overlap and to maximize the sum of scheduled jobs
performed_at = model.NewBoolVar("performed by %dh %dw %dj %dt" % (h, w, job[0], jt))
start = model.NewIntVar(h, h, "start of %dh %dw %dj %dt" % (h, w, job[0], jt))
end = model.NewIntVar(0, horizon, "end of %dh %dw %dj %dt" % (h, w, job[0], jt))
optint = model.NewOptionalIntervalVar(start, job[3], end, performed_at, "interval of %dh %dw %dj %dt" % (h, w, job[0], jt))
Full source code of working model: Model