Add log term and exponential term in objective function?
Is it possible to have exponential terms in objective function in Gurobi? I want to optimize the following objective function:
min_x L2_norm(xy) + log(b+ exp(k+x))
Gurobi does provide support for "log " and "exponential" functions in constraints, but I couldn't find anything for the objective function. I am using Gurobi's python API.

Hi,
There is unfortunately no analog for adding logarithmic and exponential functions to the objective. However, you can accomplish this by introducing a new variable to represent the corresponding objective term, then use Gurobi's general constraint functions to set this new variable equal to the nonlinear term. This uses the following relationship (assuming the minimum of \( f(x) \) exists):
$$\begin{align*} \min_x f(x) = \min_{x,y}\ &y \\ \textrm{s.t. }\ &y = f(x) \end{align*}$$
Note that Gurobi builds piecewiselinear approximations of these nonlinear functions in order to solve the problem. It might be better to construct a single piecewiselinear approximation of the univariate function \( \log(b + e^{k+x}) \) yourself. With the Python API, you can do this with the Model.addGenConstrPWL() method.
Thanks,
Eli
Please sign in to leave a comment.
Comments
1 comment