Gurobi 12.0 onward
In Gurobi 12.0, one can add a nonlinear constraint to set one variable equal to a nonlinear expression. This nonlinear expression can contain a variety of nonlinear operations, including multiplication. For example, to model \( u = x \cdot y \cdot z \) in Python:
u = model.addVar(lb=-50, ub=50, name="u") x = model.addVar(lb=-1, ub=1, name="x") y = model.addVar(lb=-5, ub=5, name="y") z = model.addVar(lb=1, ub=10, name="z") model.addGenConstrNL(u, x * y * z)
It's good practice to provide the tightest possible bounds on all variables participating in nonlinear constraints. For more programmatic examples of how to directly model nonlinear constraints in Gurobi, see the genconstrnl examples in the documentation.
Earlier Gurobi versions
Earlier versions of Gurobi support constraints containing bilinear terms like \( x \cdot y \), but do not directly support constraints containing more general multilinear terms. However, multilinear terms can be modeled using a series of bilinear constraints.
Consider the multilinear constraint
$$x \cdot y \cdot z = d,$$
where \(x\), \(y\), and \(z\) are continuous variables satisfying \(x \in [x^L, x^U]\), \(y \in [y^L, y^U]\), and \(z \in [z^L, z^U]\), and \(d\) is a constant value. To model the multilinear constraint \(x \cdot y \cdot z = d\), introduce a single auxiliary variable \( w \) and add the following constraints:
$$\begin{align*}x \cdot y &= w \\ w \cdot z &= d.\end{align*}$$
Set the lower and upper bounds of \( w \) to be \(w^L\) and \(w^U\) respectively, where
$$\begin{align*}w^L &= \min\{x^L \cdot y^L, x^L \cdot y^U, x^U \cdot y^L, x^U \cdot y^U\} \\ w^U &= \max\{x^L \cdot y^L, x^L \cdot y^U, x^U \cdot y^L, x^U \cdot y^U\}.\end{align*}$$
This idea can be generalized to any constraint containing (multivariate) monomial terms. For example, the constraint \(x^2 \cdot y \cdot z^3 = d\) can be formulated by introducing four auxiliary variables \(w_1\), \(w_2\), \(w_3\), and \(w_4\), then adding the following equality constraints:
$$\begin{align*}x^2 &= w_1 \\ w_1 \cdot y &= w_2 \\ w_2 \cdot z &= w_3 \\ w_3 \cdot z &= w_4 \\ w_4 \cdot z &= d.\end{align*}$$
Note: It is strongly recommended that finite lower and upper bounds are provided for all variables that occur in nonlinear terms in a given problem.
Comments
0 comments
Article is closed for comments.