aTan(bx)
回答済みHello,
I have a nonlinear constraint that can be written as below, where a and b are constants.
y1[i] = a * tan(b * x[i]) for i in range (m)
I am aware that there is a " addGenConstrTan" method with which I can produce a "tan(x)" constraint, but this is not sufficient in my case as I need to incorporate a and b into the equation. Plus, as the constraint applies to an array of "m" elements I am not sure if PWL can be used. Is there a way to address this?
Thank you
-
正式なコメント
This post is more than three 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 why not try our AI Gurobot?. -
Hi,
So what you mean is you not just have one constraint \( \texttt{y=tan(x)} \) but you have \( \texttt{m} \) such constraints? Then why not just add that many and use a for loop around the \( \texttt{addGenConstrTan} \) call?
Also, if you want to express a more complicated situation than \( \texttt{tan(x)} \) you can just add a new constraint and a new variable to your model and substitute. So for example, if you have \( \texttt{tan(b*x)} \) then you can use
z=b*x
tan(z)Best,
Sonja
1 -
Hello Sonja,
Thanks for your helpful answer.
1. Does a regular for loop in Gurobi act exactly in the same way as when we incorporate it into a constraint? For example, are the below cases exactly the same things or do they lead to different results? I suspect that putting Tan constraints under a for loop is undermining the impact of the rest of my constraints.
Case1:
for i in range (m):
constraint_1=model.addGenConstrTan(x[i] , y[i])
constraint_2=model.addConstrs(z[i]==h[i] for i in range (m))Case2:
for i in range (m):
constraint_1=model.addGenConstrTan(x[i] , y[i])
constraint_2=model.addConstrs(z[i]==h[i] for i in range (m))2. I also have another quick question. In my problem, I have some very small variable (on the scale of 1e-6 and even smaller), assuming that there is no way to change the scale of my variables, how can I make sure that Gurobi makes the calculations with the highest precision so I will not lose my data during the optimization?
Thank you0 -
Hi Hooman,
- No these are two different things, the first one creates m contraint_1 objects and m constraint_2 objects. The second one created m constraint_1 objects and m*m constraint_2 objects, but only m different once. Why would you want to create m times the same constraint? Also, i is not well defined in Case2. If you are not sure what the output of some construction is, you can start with a very small number of constraints and variables and print out the LP file and then look at it.
- Do you mean you have continuous variable with super small bounds? How does the numeric of the rest of the model look like? If this is so tricky you can try to use the NumericFocus parameter to tell Gurobi right away that you are expecting problems.
Best,
Sonja
0
投稿コメントは受け付けていません。
コメント
4件のコメント