In this article, we discuss approaches for modeling piecewise bilinear and multilinear functions depending on two or more variables. Gurobi's support for piecewise-linear functions is limited to univariate functions, but it can still be useful for approximating multivariate functions.

Consider the following multivariate function:

$$\begin{align*} f(x, t) &= \sigma(t) \sqrt{x}. \end{align*}$$

We can approximate this function with the following approach.

1. Construct a piecewise-linear approximation of \( \sigma(t) \). E.g., \( u = \sigma(t) \). In Python, this can be done with the Model.addGenConstrPWL() method.

2. Construct a piecewise-linear approximation of \( \sqrt{x} \). E.g., \( w = \sqrt{x} \).

3. Introduce a new auxiliary variable to the model (say, \( y \)) to represent \( f(x, t) \). Add a bilinear constraint to set \( y \) equal to the product of the two piecewise-linear approximations: \( y = uw \).

Alternatively, you can build such a piecewise-linear approximation from scratch. For example, a piecewise-linear function of two variables can be built by triangulating the three-dimensional surface corresponding to the function graph (for example, see here). In this case, you need to keep track of which "supporting triangle" (simplex, more generally) the argument of the function lies in. This can be done with binary indicator variables.

### Further information