Conditional addGenConstrLogA for pH calculation
Awaiting user inputHi there,
in my model I compute the pH of a solution with an addGenConstrLogA-function. According to the equation pH = -log([H+]), with [H+] being the concentration of protons, which is already tightly bound to the expected limits of my model, (1e-10, 4.168694e-5).
Unfortunatly due to the exponential nature of the log function at these values, I get very high approximation errors, even with a tight funcPieceError, or a high amount of funcPieces.
According to https://www.gurobi.com/documentation/current/refman/constraints.html#subsubsection:GenConstrFunction , I want to implement 5 LogA approximations, depending on the value of the proton concentration, to make the approximation tighter. That would look something like this:
model.addGenConstrLogA(model.getVarByName("proton_balance_e5"), model.getVarByName("pH_negative"), 10.0, "log10", "FuncPieces=10000")
model.addGenConstrLogA(model.getVarByName("proton_balance_e6"), model.getVarByName("pH_negative"), 10.0, "log10", "FuncPieces=10000")
model.addGenConstrLogA(model.getVarByName("proton_balance_e7"), model.getVarByName("pH_negative"), 10.0, "log10", "FuncPieces=10000")
model.addGenConstrLogA(model.getVarByName("proton_balance_e8"), model.getVarByName("pH_negative"), 10.0, "log10", "FuncPieces=10000")
model.addGenConstrLogA(model.getVarByName("proton_balance_e9"), model.getVarByName("pH_negative"), 10.0, "log10", "FuncPieces=10000")
Any help, or a quick example would be highly appreciated!
-
Official comment
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. -
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.
Comments
2 comments