I am working on a scheduling problem in OR-Tools using the CP-SAT solver.

I'm working with python but I managed to rebuild this solution as starting point: Optimal way to ensure optional intervals are consecutive in OR-Tools

Just like in that problem I also have the constraint, that the jobs are consecutive. This works already.

My first problem is really easy in my mind, but somehow I cant make it work: the first job on each machine MUST start at 0.

Second problem: lets say I produce n colors of the same product. Every one of these $n$ colors has a maximum $i$, which is the maximum number of jobs of the same color I can build in sequence on the same machine.

My solution pretty much depends on my x[job,machine] dict where x[job,machine] is true if job is performed on machine.


1 Answer 1


for 1) Look at this literal in the jobshop with setup times. You just need to add:

model.Add(start_of_job == 0).OnlyEnforceIf(start_lit)

For 2) For each color, add for each job a variable ranging from 0 to max_sequence_length for this color.

For each arc, you know if job_i has the same color as job_j. If true, the

model.Add(sequence_length[color][j] = sequence_length[color][i] + 1).OnlyEnforceIf(lit)


model.Add(sequence_length[color_i][j] == 0).OnlyEnforceIf(lit)
model.Add(sequence_length[color_j][j] == 1).OnlyEnforceIf(lit)

And do not forget to initialize all sequence lengths vars with the start_lit literal.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.