XiongPengNUS / rsome

Robust Stochastic Optimization Made Easy
GNU General Public License v3.0
282 stars 54 forks source link

How to handle Second-Order Conic unsupported list #30

Closed eezlin closed 1 year ago

eezlin commented 1 year ago

I want to write the Second-Order Conic program of the constraint via RSOME. Such as: $$ ||a,b,c||_2<=d $$ But it suggests that the list can't work on norm, how should I handle it, thanks.


Traceback (most recent call last): File "C:/Users/ASUS/Desktop/test/2nd/Distflow_SOCP_robust.py", line 75, in model.st(rso.norm([P2[i,t], Q2[i,t], W2[i,t]]) <= I[i,t] + U[first_node[i],t]) File "D:\ProgramData\Anaconda3\lib\site-packages\rsome\subroutines.py", line 245, in norm return affine.norm(degree) AttributeError: 'list' object has no attribute 'norm'

GalPerelman commented 1 year ago

@VictorLin-z did you try converting the list to np.array? model.st(rso.norm(np.array([P2[i,t], Q2[i,t], W2[i,t]])) <= I[i,t] + U[first_node[i],t])

eezlin commented 1 year ago

When I corrected it according to your suggestion, he still reported an error. It is possible that P2, Q2, and W2 are variables. At the same time, I merged the 32$\times$24 variables into 1$\times$768, and then compared with the 1$\times$768 variables with the bi-norm of 3$\times$768, the gurobi solver shows that the model has no feasible solution or is unbounded. The model I have implemented on gurobi, I want to make robust based on this. Maybe I need to do the dual analysis myself.


Traceback (most recent call last): File "C:/Users/ASUS/Desktop/test/2nd/Distflow_SOCP_robust.py", line 81, in model.st(rso.norm(np.array([P2[i,t], Q2[i,t], W2[i,t]]),2) <= I[i,t] + U[first_node[i],t]) File "D:\ProgramData\Anaconda3\lib\site-packages\rsome\subroutines.py", line 245, in norm return affine.norm(degree) AttributeError: 'numpy.ndarray' object has no attribute 'norm'

XiongPengNUS commented 1 year ago

Hi @VictorLin-z there is no direct way to formulate a second-order cone constraint using lists of expressions. However, you could define an intermediate variable array to address this issue. See the example below:

y = model.dvar(3)
model.st(y[0] == a, y[1] == b, y[2] == c)
model.st(rso.norm(y) <= d)
eezlin commented 1 year ago

I used your method and found that it worked, but still reported an error. The error message is "warnings.warn('No feasible solution can be found.')", maybe I need to modify my model. Thank you for answering the question.