About the Matrix subtraction in gurobi
回答済みHi,
Can someone tell me how to express this constraint in gurobi? I didn't find a description in the API documentation. If you can help me, I will be very grateful to you. This is my constr.

This is my code. (q[j] - qr[j]) Subtraction between two matrices does not seem to be allowed in gurobi.
code
model = grb.Model('')
qr = np.array([[500, 500, 100], [500, -500, 100], [-500, 500, 100], [-500, -500, 100]])
s = np.array([[-250, -250, 0], [-250, 250, 0], [250, -250, 0], [250, 250, 0]])
q = model.addVars(4, 3, lb=-500, vtype=GRB.CONTINUOUS, name='q')
k = model.addVars(4, vtype=GRB.CONTINUOUS, name='k')
model.update()
for j in range(4)
model.addConstr(k[j] <= np.linalg.norm(qr[j] - s[1]) ** 2 + 2 * (qr[j] - s[1]).transpose() *(q[j] - qr[j]))
0
-
正式なコメント
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,
It is currently not possible to perform vector operations with \(\texttt{Var}\) objects. However, you can always write vector operation as sums. In your case, this would be
for j in range(4):
model.addConstr(k[j] <= np.linalg.norm(qr[j] - s[1]) ** 2 + 2 * (grb.quicksum( (qr[j][i] - s[1][i])*(q[j,i] - qr[j][i]) for i in range(3))) )Best regards,
Jaromił0 -
Hi Jaromił,
Thank you for your detailed answer. Thanks to your help, I have successfully solved this problem now.
Best regards,
Yanbo
0
投稿コメントは受け付けていません。
コメント
3件のコメント