Skip to main content

Conditional addGenConstrLogA for pH calculation

Awaiting user input

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • Gurobi Staff

    Hi Tim,

    You could introduce 5 auxiliary binary variables \(b_i\) and a constraint stating that exactly \(1\) of these binaries is \(>0\).

    \[\begin{align*}
    \sum_i b_i &= 1\\
    b_i &\in \{0,1\}
    \end{align*}\]

    You can then use these binary variables in indicator constraints to model

    \[\begin{align*}
    b_i = 1 &\rightarrow y_i = \log(x)\\
    b_i = 0 &\rightarrow y_i = 0
    \end{align*}\]

    You can then get the final value by adding all \(y_i\) variables.

    In your constraints, you always use the same argument variable

    model.getVarByName("pH_negative")

    This makes 4 out of the 5 constraints redundant. Is this a typo or is some piece of information missing?

    Best regards, 
    Jaromił

    0

Post is closed for comments.