Skip to main content

How to add log and exponential term in objective function?

Answered

Comments

1 comment

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi Lena,

    Gurobi does not natively support nonlinear function such as \(\log, \exp\). However, supports piecewise-linear approximations of these functions. You can add a constraint \(y = \log(x)\) via the addGenConstrLog method and a constraint \(y = \exp(x)\) via the addGenConstrExpr method. Note that both method accept only a single variable as input and output. This means that you have to introduce auxiliary variables in order to work with general constraints. For example, in order to implement \(\min x + \exp(\sum_i y_i)\), you have to add 2 auxiliary variables and 2 constraints to model it as

    \[\begin{align*}
    \min\,\,\, &x + z\\
    \text{s.t.}\,\,\, & z = \exp(w)\\
    & w = \sum_i y_i
    \end{align*}\]

    The only issue I see is the modeling of the term \((-1)^{y}\). Gurobi currently does not support a power term with negative base, cf. addGenConstrExpA method. So unless you can reformulate your objective expression, it is not possible to model it in Gurobi at the moment.

    Best regards, 
    Jaromił

    0

Please sign in to leave a comment.