Quadratic equality constraints Python
回答済みI am implementing a model in Gurobi, and I noticed that quadratic equality constraints are automatically cast to quadratic inequality constraints by Gurobi. However, I need quadratic equality constraints and not quadratic inequality constraints.
Can someone explain why this is happening? Will an optimal solution now only satisfy the quadratic inequality constraints or also the quadratic equality constraints?
I have added a minimal code example where the issue arises. Note that this problem itself does not make any sense, but I tried to find the most simple example where I saw the issue arise.
import gurobipy
model = gurobipy.Model("Example")
model.setParam('NonConvex', 2)
#Variables
NR_VS = 2
x = model.addVars(NR_VS, vtype=gurobipy.GRB.CONTINUOUS, lb=0, ub=2, name="x")
y = model.addVars(NR_VS, vtype=gurobipy.GRB.CONTINUOUS, lb=0, ub=2, name="x")
#Objective
model.setObjective(x[0], gurobipy.GRB.MAXIMIZE)
#Constraints
for i in range(NR_VS):
model.addConstr(sum([x[j] * y[j] for j in range(NR_VS)]) == x[i], "x[i] = x[j]*y[j]")
model.update()
model.display()
model.optimize()
-
正式なコメント
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 Nan,
This may be a bug in the display function. If the equality really was being converted to an inequality then constraints of the form
sum([x[j] * y[j] for j in range(NR_VS)]) == -1
would be considered feasible, since the corresponding inequality could be satisfied by setting all variables to zero, but if you try and solve this it will be reported as infeasible.
I will check with our developers and confirm this for you.
- Riley
0 -
If you want to check your model, we recommend using Model.write(), for example model.write("model.lp"). You can then display the lp file for example with print(open("model.lp", "r").read()).
Note that display() is not a Gurobi Python API function and may not work as expected.
0 -
Thank you, Marika and Riley. I now use model.write() and indeed, the constraint that I see is:
- x[0] + [ x[0] * x[0] + x[1] * x[1]] = 0
0
投稿コメントは受け付けていません。
コメント
4件のコメント