CVXPY中矩阵求解线性规划

2024-03-28 10:07:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python3中使用CVXPY来尝试在X(N乘T矩阵)中建模以下线性程序。让

  • R是一个N×1矩阵,其中每一行是{}中整行值的总和。在
  • P是根据X定义的1×N矩阵,例如P_t = 1/(G-d-x_t)。在

我想解决这样一个理想:

minimize (X x P)

subject to:

The sum of reach row i in X has to be at least the value in R_i

Each value in X has to be at least 0

有什么想法吗?我有以下代码,但没有得到任何运气:

from cvxpy import *
X = Variable(N,T)
P = np.random.randn(T, 1)

R = cumsum(X,axis=0) # using cumsum because 
http://www.cvxpy.org/en/latest/tutorial/functions/index.html#vector-matrix-functions


objective = Minimize(sum_entries(square(X*P))) #think this is good

constraints = [0 <= X, cumsum(X,axis=0) >= R]
prob = Problem(objective, constraints)

Tags: toinvalue矩阵befunctionsathas