Conditional addGenConstrLogA for pH calculation
Awaiting user inputHi there,
in my model I compute the pH of a solution with an addGenConstrLogAfunction. 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, (1e10, 4.168694e5).
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!

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
Please sign in to leave a comment.
Comments
1 comment