本文介绍了约束不遵循CVXPY中的DCP规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用CVXPY解决此问题,但我不知道为什么会收到以下错误消息:
I want to solve this problem using CVXPY but I don't know why I get the following error message:
我想我的约束条件不是DCP。有什么方法可以在DCP中对此建模吗?
I guess my constraints are not DCP. Is there any way to model this in DCP?
n_k = [10000, 20000]
request_rate = [15, 10]
p_k_1 = np.random.rand(n_k[0])
p_k_2 = np.random.rand(n_k[1])
#params
p_k_param_1 = cvx.Parameter(1, n_k[0], sign="positive")
p_k_param_1 = np.array(p_k_1)
p_k_param_2 = cvx.Parameter(1, n_k[1], sign="positive")
p_k_param_2 = np.array(p_k_2)
request_rate_param = cvx.Parameter(2, sign="positive")
request_rate_param = np.array(request_rate)
#varibales
c_k = cvx.Variable(2)
T_k = cvx.Variable(2)
constraints = [ cvx.sum_entries(c_k) <= 10000,
c_k >= 0,
c_k[0]==cvx.sum_entries(1-cvx.exp(-request_rate_param[0]*T_k[0]*p_k_param_1)),
c_k[1]==cvx.sum_entries(1-cvx.exp((-request_rate_param[1]*T_k[1])*p_k_param_2))]
h_k_1 = request_rate_param[0] * cvx.sum_entries((p_k_param_1 * (1-cvx.exp(-request_rate_param[0]*T_k[0]*p_k_param_1))))
h_k_2 = request_rate_param[1]* cvx.sum_entries(p_k_param_2 * (1-cvx.exp(-request_rate_param[1]*T_k[1]*p_k_param_2)))
obj = cvx.Maximize(cvx.log(h_k_1) + cvx.log(h_k_2))
prob = cvx.Problem(obj, constraints)
prob.solve(verbose=True)
推荐答案
您的实用程序功能:
cvx.log(h_k_1) + cvx.log(h_k_2)
不是凸的。
规则可能会告诉您可以在解决方案中找到哪些内容。
These rules might be able to tell you what you can sub in your solution.
这篇关于约束不遵循CVXPY中的DCP规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!