使用CVXOPT或CVXPY进行凸面编程

时间:2015-03-20 19:15:39

标签: python optimization cvxopt convex-optimization cvxpy

我需要用Python解决CVXOPT或CVXPY的优化问题,但我遇到了困难。目标函数是

Minimize Sum(a*x^2+b/x)

受以下约束

5 <= x < 40;

sum(v/d)<=T

其中,向量x是优化变量,给出了向量abT是给定的标量。

1 个答案:

答案 0 :(得分:3)

以下代码解决了CVXPY中的问题。我以为你的意思是sum(x/d) <= T

# Replace these with your values.
n = 2
a = 2
b = 2
d = 2
T = 1000

import cvxpy as cvx

x = cvx.Variable(n)
obj = cvx.sum_entries(a*x**2 + b*cvx.inv_pos(x))
constr = [5 <= x, 
          x <= 40,
          cvx.sum_entries(x/d) <= T]
prob = cvx.Problem(cvx.Minimize(obj), constr)
prob.solve()