Jacek
Jacek

Reputation: 1088

adding a NOT-constraint in pyscipopt

I'd like to add a NOT-constraint to my PySCIPOpt model. I can see andConsAnd, addConsOr and addConsXor but there isn't one for the NOT operator. What would be the easiest way to add a NOT-constraint?

I came up with:

x = model.addVar('B')
not_x = model.addVar('B')

model.addCons(not_x == (x - 1) * (x - 1))

but that seems ugly.

The reason I need not_x is because I'd like to add it later to a conjunction, like:

model.addConsAnd([not_x, y], True)

But, as far as I can see, PySCIPOpt interface does not work if I do it using Python not operator:

model.addConsAdd([not x, y], True)

so the above line breaks the Kernel in my jupyter notebook.

Any help appreciated.

Upvotes: 0

Views: 243

Answers (1)

Erwin Kalvelagen
Erwin Kalvelagen

Reputation: 16724

The expression not x for a binary variable x is identical to 1-x. This is used extensively in mixed-integer programming models.

Upvotes: 1

Related Questions