數值計算·第八集:二階錐規劃(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)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章