# Decision Optimization

View Only

## docplex Python - Constraints with bitwise operators

• #### 1.  docplex Python - Constraints with bitwise operators

Posted Mon May 16, 2022 02:38 PM
Dear IBM Community,

I'm using docplex in order to solve a model in Python. I would like to add a constraint as follows:

where xi is a binary variable in our Model, and Mi,j is a matrix of zeros and ones (it is a constant). x = x1, x2, ... xm should be a list of zeros and ones corresponding to the above constraint. The addition and multiplication operations are actually bitwise addition and multiplication (computed with operators ^ and & in Python).

I'm having difficulties in understanding how I should write this expression. Specifically:
• It is supported to use ^ and & operators or we have a workaround for this?
• It is mandatory to have this expression written inline or we have other methods to pass this expression?
Can you please let me know what is a good approach to write this constraint?

Thank you!

------------------------------
------------------------------

• #### 2.  RE: docplex Python - Constraints with bitwise operators

Posted Mon May 16, 2022 02:44 PM

There are a number of examples for DOcplex, and they are referred to from the documentation at http://ibmdecisionoptimization.github.io/docplex-doc/index.html#mathematical-programming-modeling-for-python-using-docplex-mp-docplex-mp.  Did you study the examples in the section examples/mp/modeling already?

------------------------------
Xavier
------------------------------

• #### 3.  RE: docplex Python - Constraints with bitwise operators

Posted Tue May 17, 2022 09:27 AM
Edited by Andrada Tue May 17, 2022 09:29 AM
Dear Xavier,

Hope you are well!

Thank you for sharing the location where we can find modeling examples for Docplex. It seems that Docplex automatically understands how to perform the correct operations if we specify the Variables as binary.

Exact location for Official Docplex modeling examples: http://ibmdecisionoptimization.github.io/docplex-doc/mp/samples.html
```