数值计算·第八集:二阶锥规划(CVXPY版)
作者:互联网
Second-order cone program(二阶锥规划)
标准形式:-A second-order cone program (SOCP) is an optimization problem of the form:
#SOCP
import cvxpy as cp
import numpy as np
#problem datam
m,n,p,n_i = 3,10,5,5
np.random.seed(1)
F = np.random.randn(p,n)
f = np.random.randn(n)
x0 = np.random.randn(n)
g = F@x0
A = []
b = []
c = []
d = []
for i in range(0,m):
A.append(np.random.randn(n_i,n))
b.append(np.random.randn(n_i))
c.append(np.random.randn(n))
d.append(np.linalg.norm(A[i]@x0+b,2)-c[i].T@x0)
#problem variable
x = cp.Variable(n)
#constraints
soc_constraints = [cp.SOC(c[i].T@x + d[i], A[i]@x + b[i]) for i in range(m)]
#objective
objective = cp.Minimize(f.T@x)
#construct the problem
prob = cp.Problem(objective,soc_constraints+[F@x == g])
#solve
prob.solve(solver = cp.,verbose = True)
标签:CVXPY,randn,第八集,random,二阶,np,x0,cp,append 来源: https://blog.csdn.net/Miracle0_0/article/details/100062308