Skip to main content

nonlinear programming problem

Answered

Comments

2 comments

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    You can model a division as described in How do I divide by a variable in Gurobi?

    The log term can be introduced by the addGenConstrLog method.

    Please note that the addGenConstrLog method takes only exactly one optimization variable as argument variable. This means that you will have to introduce a couple of auxiliary variables. In the end, you will have to model something like

    \[\begin{align*}
    z_1 &= \text{probabilities}\\
    z_2 &= 1 - z_1\\
    z_3 &= \log(z_1) \quad \leftarrow \log(\text{probabilities})\\
    z_4 &= \log(z_2) \quad \leftarrow \log(1 - \text{probabilities})\\
    z_3 &= z_4 \cdot z_5 \quad \leftarrow z_5 = \frac{z_3}{z_4}
    \end{align*}\]

    It is important to make sure that variables \(z_3\) and \(z_4\) are \(>0\) to avoid \(\log(0)\). This means that you have to set the lower bounds for the auxiliary variables manually to something \(>0\) and this implies that your probabilities variables cannot attain values \(1\) and \(0\). You could account for this directly when defining these variables. You could set the bounds to something like

    probabilities = model_de.addVars(n, lb=1e-4, ub=1-1e-4, vtype=GRB.CONTINUOUS, name="probabilities")

    If you are using Gurobi version 11, then you can set the FuncNonlinear parameter to 1 to tell Gurobi to handle the \(log\) function via dynamic piecewise-linear approximation, i.e., as a nonlinear function. Please refer to the documentation of General Constraints for more details.

    Best regards, 
    Jaromił

    1
  • LAN Happy
    First Comment
    First Question

    thx!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!ursoooonice

    0

Please sign in to leave a comment.