Why does it take a long time to establish this matrix constraint?
進行中I would like to know why it takes a long time to establish the second-order cone constraint shown in the following code. Here, a_x
has dimensions (1, 33), DRCC_cov_load[t]
is a (33×33) positive semi-definite matrix, and a_x_T
is the transpose of a_x
. What puzzles me is that establishing other second-order cone constraints of this form (with different a_x
and b_x
) takes almost negligible time, but establishing this particular constraint takes about 20 seconds. I am using an i9-14900HX CPU. I wonder if the modeling speed is related to the sparsity of the matrix? Is there any way to reduce the time required to establish this constraint?
a_x , a_x_T, b_x = B_INV_P_V[i:i+1,:] @ delta_p_t[t], delta_p_t[t].T @ B_INV_P_V[i:i+1,:].T, V_MAX - Bus_V[t,i] # affine function of uncertainty
lhs = model.addVar()
model.addConstr(lhs == b_x - a_x @ DRCC_mean_load[t])
model.addConstr(DRCC_cof*(a_x @ DRCC_cov_load[t] @ a_x_T) <= lhs * lhs)
-
Hi Jie,
Any chance of creating a reproducible example using numpy.save to write the data to file?
- Riley
0 -
https://1drv.ms/u/c/f3004033f0c5eb61/EXSrJgerUQZCiy6dAO7zcyIBtaTUnggCXcqKpQBBHTWteA?e=yrF9Jt
Thank you so much for your response. I've uploaded the part of my code that takes a long time to run, along with the data used (saved in .npy format), to this OneDrive link. I'd really appreciate it if you could take a look and suggest any ways to improve the code's execution speed. Thanks again!
0 -
When I run the constraint I get the following warning:
Chained matrix multiplications of MVars is inefficient, collect numeric terms first when building expressions
Do you see this warning with your version of Gurobi?
What puzzles me is that establishing other second-order cone constraints of this form (with different
a_x
andb_x
) takes almost negligible timeWere the a_x and b_x in this case MVars? In your current code they are MLinExpr, which is why the warning is being issued.
0 -
Thank you for your reply, when I define a_x and b_x as Mvar the speed of the computation is greatly improved!
In my complete code, I used the
warning
library, which prevented this warning from appearing. However, when I uploaded a simplified version of the code, I encountered the warning. I referred to the link https://support.gurobi.com/hc/en-us/articles/9191776582801-What-should-I-do-upon-RuntimeWarning-Chained-matrix-multiplications-of-MVars, but the chained matrix multiplication only contains a single numeric term, so the suggested method from that link did not work.I updated the code in the new OneDrive link to include faster computation for comparison. I defined a_x and b_x as MVar and found that the warning disappeared and the computation speed improved.
Hopefully, the Gurobi team can optimize this further so that different programming styles can have the same computation speed, thanks again!
0
サインインしてコメントを残してください。
コメント
4件のコメント