hyperbolic sine of the elements of X
AnsweredHi,
Does Gurobi Python, has sinh(x), which stands for hyperbolic sine of the elements of X.
I utilized Model.addGenConstrSin, but when I searched on the internet I found that this attribute is different from sinh(x) that I am looking to implement, and therefore, the result is not good.
Could you please let me know if gurobi has an attribute regarding this.
Thank you in advance,
#calculating the size of the uncertainty set under the assumption that the uncertainty is
#bounded and symmetric which is satisfied in this example
#parameters
eps=0.5
mu=0.1 #abs(E(r.v)= 0.1)
j=1
#Set of Constraints
m.addGenConstrSin(theta,x)
m.addGenConstrCos(theta,y)
m.addConstr(t == x+y)
m.addGenConstrLog(t,f)
m.addConstr(-theta*delta_gmf + j*f <= math.log(eps))
Z=delta_gmf
m.setObjective(Z, GRB.MINIMIZE)
m.params.NonConvex = 2
m.optimize()
-
Hi,
The hyperbolic sine function equals \(\sinh(x) = \frac{e^{x} - e^{-x}}{2}\). You can use the method Model.addGenConstrExp() to model the natural exponential function. See the example script below:
import gurobipy as gp
from gurobipy import GRB
m = gp.Model()
sinh = m.addVar(lb=-GRB.INFINITY, name="sinh")
# It is important to set the lb and ub of the x and x_minus variables
# to the tightest possible values depending on your application
x = m.addVar(lb=-GRB.INFINITY, name="x")
x_minus = m.addVar(lb=-GRB.INFINITY, name="x_minus")
y = m.addVar(name="y")
y_minus = m.addVar(name="y_minus")
# Define y = exp(x)
m.addGenConstrExp(x, y)
# Define y_minus = exp(x_minus) = exp(-x)
m.addGenConstrExp(x_minus, y_minus)
# Define the relationship between x and x_minus
m.addConstr(x == -1*x_minus)
# Define hyperbolic sine function
m.addConstr(sinh == 0.5 * (y - y_minus))Best regards,
Maliheh
1 -
Hello Ms. Maliheh,
Thank you so much for your feedback, it is really helpful.
I have just noticed that a mistake has been made on your shared code;
which I think should be like the following; (please correct me if I am wrong).
# Define the relationship between x and x_minus m.addConstr(x_minus == -1*x)
Best Regard,
0 -
Hi,
If you multiply both sides of the constraint \(x_{\text{minus}} = - x\) by -1, we get the constraint \(-x_{\text{minus}} = x\). Therefore, your version is mathematically equivalent to the constraint implemented in our script.
Best regards,
Maliheh
0
Please sign in to leave a comment.
Comments
3 comments