0

I am working on an optimization problem with cvxpy. And I need to create a SOC(second order cone) constraint. The way described in cvxpy documents is like following:

We use cp.SOC(t, x) to create the SOC constraint ||x||_2 <= t. where t is the scalar part of the second-order constraint, x is a matrix whose rows/columns are each a cone.

Here is the standard way how cvxpy solve a SOCP problem.

But now i need to extract Variable from different places.

import cvxpy as cvx

Y = cvx.Variable(3)
Z = cvx.Variable(3)
T = cvx.Variable(3)
soc_constraints = []
for in range(3):
   t = T[i]
   x = np.matrix([Y[i], Z[i]])
   soc_constraints += [cvx.SOC(t, x)]

But I get one error here.

AttributeError: 'matrix' object has no attribute 'variables'

I suppose x should be a cvxpy expression. But how can i create a SOC constraint out of different Variable vectors. Some help would be appreciated.

Black Bob
  • 105
  • 1
  • 13
  • 1
    Looks like you are misusing `np.matrix()` for concatenation / matrix-building. Just use any of cvxpy's functions to do that (like `hstack`). Additionally, `np.matrix` is always calling for trouble in modern code as numpy's matrices are not numpy arrays and the former is mostly deprecated in most codes. – sascha May 05 '19 at 15:31
  • You are right. I am new to cvxpy and i think `hstack` is what i need. Thanks a lot. – Black Bob May 06 '19 at 05:33

0 Answers0