Skip to content
Advertisement

Adding an or-statement to an OR-Tools constraint (CP-SAT solver)

So I’m trying to build a scheduling tool in OR-tools similar to the employee scheduling example. However, in my case there are ten shifts to cover, and I would like to prevent people from having a ten hour workday by making sure either the first two shifts are off, or the last two shifts are off.

I would like to do something like this, but it keeps saying the solution is INFEASABLE.

JavaScript

Is it really INFEASABLE or is this piece of code not doing what I think it is doing?


Thanks Laurent for helping me find the answer! For future references, in code it would look like this:

JavaScript

Advertisement

Answer

Please read https://github.com/google/or-tools/blob/stable/ortools/sat/doc/channeling.md

In a nutshell, or, and, min, max python keywords are not correctly interpreted. In your case, sum() == 0, will be on object, thus always evaluated to True when the python code is parsed.

You need to create all intermediate Boolean variables, and add you bool_or constraint on those.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement