Skip to main content

How to add log and exponential term in objective function?

Answered

Comments

3 comments

  • 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
  • Ryan Trusler
    Gurobi-versary
    First Comment

    Hi Jaromił,

    Thanks for making this post. I am struggling to find any documentation for how to add this constraint (addGenConstrExpA) in Julia (JuMP specifically). Is there a page that I am missing? 

    Thanks

    0
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi Ryan,

    I am not a Julia or JuMP user. However, according to the github repo of Gurobi.jl, the function addGenConstrExpA is supported, cf. Gurobi.jl/libgrb_api.jl.

    Best regards, 
    Jaromił

    0

Please sign in to leave a comment.