about the constraints changed with variables
ユーザーの入力を待っています。Eexcuse me, in my problem, I have several constraints changed with variables. For example I need to achieve the model has following logic:
if p[0]>=4:
model.addConstr(p[1]<=1.5)
else:
model.addQConstr((p[1]-2.5)**2+(p[0]-4)**2<=16)
the logic of the problem is like this where p is my variable. How can I code this nonlinear constraint.
Thanks
-
正式なコメント
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
You can do it via indicator constraints. Perhaps this post will give you an idea of how to go about this.
Additionally, I would suggest that you have a look at this entry concerning the creation of quadratic constraints, and make sure that your Python syntax is correct.
Best regards
Jonasz0 -
Thanks for your suggestion, I tried to use a binary variable and use indicator constraints, but the constraint is quadratic. So I added a new variable to define the quadratic equation, it works. I really appreciate your help!
0 -
Actually, my objective is also changed with variables, like :
if p[9,0]>=4:
objective=max p[9,1]
else:
objective=max p[9,0]
the expression is simplified.The objective function is segmented and nonlinear. Here the indicator constraints don't work, I also wonder how could I settle this.
0 -
I am afraid you can't change the objective this way. But perhaps you can find a way to reformulate your objective in such a way that the change is not required?
Best regards,
Jonasz0
投稿コメントは受け付けていません。
コメント
5件のコメント