问题
I want to solve this problem using CVXPY but I don't know why I get the following error message:
DCPError: Problem does not follow DCP rules.
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)
回答1:
Your utility function:
cvx.log(h_k_1) + cvx.log(h_k_2)
is not convex.
These rules might be able to tell you what you can sub in your solution.
来源:https://stackoverflow.com/questions/44343243/constraints-do-not-follow-dcp-rules-in-cvxpy