我想使用 CVXPY 解决这个问题,但我不知道为什么会收到以下错误消息:
DCPError:问题不遵循 DCP 规则。
我想我的约束不是 DCP。有没有办法在 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)