• Gurobi Staff

Hi Umair,

Currently the best way is to reformulate such multilinear products as bilinear products by the introduction of auxiliary variables.
For example, you can reformulate $$x \cdot y \cdot z = 0$$ as
\begin{align} x \cdot \omega &= 0 \\ y \cdot z &= \omega \\ x \in &[x^L, x^U] \\ y \in &[y^L, y^U] \\ z \in &[z^L, z^U] \\ \omega \in &[\min\{y^L \cdot z^L, y^L \cdot z^U, y^U \cdot z^L, y^U \cdot z^U\},\\ &\max\{y^L \cdot z^L, y^L \cdot z^U, y^U \cdot z^L, y^U \cdot z^U\}] \end{align}

Note that I explicitly added bounds on all variables as this is recommended when working with nonlinear models.

Best regards,
Jaromił

Dear Jaromil Najman

Thank you so much for your helping and kind response. I got the idea.

Can I declare such a variable which is the product of two variables, like  w = y.z , if yes, how can I do that?

For example  (I am using the python interface)

w = model.addVar( y.z , name = "temp" ) ?

Or I have to add a constraint for this purpose?

model.addConstr( w == y.z, "temp") ?

Furthermore, while declaring/adding a variable, can I use  min/max{x1,x2,..} constraint for giving lower/upper bounds, for example

w = model.addVar( lb=min{x1.x2, x3.x4}, ub= max{x5.x6, x7.x8}, obj=0, vtype = GRB.INTEGER, name = "temp") ?

Umair

• Gurobi Staff

Hi Umair,

You cannot directly declare the variable as a product of two variables. You have to declare an additional variable and the corresponding equality constraint. You can use the functions you mention in your example. For the bounds you can use the variable attributes but it may be easier to just keep track of the bounds by hand. You can also directly use python min/max functions to determine the values of the new variable's bounds.

For your example, let's assume you have the expression $$x \cdot y \cdot z$$ with $$x,y,z \in [-2,2]$$.
The code for reformulation would then be would then be

w = m.addVar(min(-2*-2,-2*2,2*-2,2*2),max(-2*-2,-2*2,2*-2,2*2),vtype=GRB.CONTINUOUS, name="w")m.addConstr(w==x*y,name="aux_constr")

The expression $$x\cdot y$$ on the right hand side of the equality constraint is a QuadExpr making your problem a quadratic one. To make Gurobi solve such problems, please set the parameter NonConvex to 2.

In the above I assumed that all variables are continuous. This works analogously for discrete variables.

Best regards,
Jaromił

Dear Jaromil

I got it. Thank you so much.

Umair