I am a graduate student just learned the convex optimization. I am solving a problem about convex using cvxpy. However when I structured the problem and used the solver model the compiler told me it was not a DCP problem.I just realized it was a non-convex problem. I came here to ask if this problem can be converted to a convex problem. The problem description goes: I wanna optimize the sum of 3 bit rates, the bit rate forum goes like this: $R_i = \alpha_iW_ilog(1+\beta_iP_i/W_i)$,inside $P_i$ and $W_i$ are variable , $\alpha_i$ and $\beta_i$ are constant(different for 3 cases).The 6 parameters are $\alpha_1 = 2$,$\alpha_2 = 2.4$,$\alpha_3 = 2.8$ and $\beta_1 = 2$,$\beta_2 = 2.4$,$\beta_3 = 2.8$. What is more there are 2 contraints: $\sum P_i = 0.5$ and $\sum W_i = 1$. The problem is how to allocate $P_i$and $W_i$ to maximize the $\sum _1 ^ 3R_i$. I firstly tried to structured the problem into cvxpy and solved, the code goes like this:
import cvxpy as cp
import numpy as np
def bit_rate(alpha, beta, p, w):
return alpha * w * cp.log(1 + beta * p / w)
# Create scalar optimization variables.
p_1 = cp.Variable()
p_2 = cp.Variable()
p_3 = cp.Variable()
w_1 = cp.Variable()
w_2 = cp.Variable()
w_3 = cp.Variable()
r_1 = bit_rate(2, 2, p_1, w_1)
r_2 = bit_rate(2.4, 2.4, p_2, w_2)
r_3 = bit_rate(2.8, 2.8, p_3, w_3)
# Create constraints.
constraints = [p_1 + p_2 + p_3 == 0.5,
w_1 + w_2 + w_3 == 1,
p_1 >= 0, p_2 >= 0, p_3 >= 0,
w_1 >= 0, w_2 >= 0, w_3 >= 0]
# Form objective.
obj = cp.Maximize(r_1 + r_2 + r_3)
# Form and solve problem.
prob = cp.Problem(obj, constraints)
prob.solve() # Returns the optimal value.
print("status:", prob.status)
print("optimal value", prob.value)
print("p optimal var", p_1.value, p_2.value, p_3.value)
print("W optimal var", w_1.value, w_2.value, w_3.value)
But it turned out the bug
The objective is not DCP. Its following subexpressions are not:
2.0 * var0 / var3
2.4 * var1 / var4
2.8 * var2 / var5
I figured it out that the $P_i/W_i$ is the problem, it is not convex, So I came to ask if this problem can be converted to a convex optimization problem and use cvxpy to solve.Thanks for attention!
This is not a full answer, but it's too long for a comment. I think it will be more clear if you write your optimization problem like this:
\begin{align} \text{maximize} & \quad \sum_{i=1}^3 \alpha_i W_i \log(1+\beta_iP_i/W_i) \\ \text{subject to} & \quad \sum_{i=1}^3 P_i = 1/2, \\ & \quad \sum_{i=1}^3 W_i = 1. \end{align} The optimization variables are the real numbers $P_i, W_i$ (for $i = 1, 2, 3$). The values of the parameters $\alpha_i$ and $\beta_i$ are $\alpha_1 = 2, \alpha_2 = 2.4, \alpha_3 = 2.8$ and $\beta_1 = 2, \beta_2 = 2.4, \beta_3 = 2$.
To recognize this problem as convex, it seems helpful to note that the function $$ f(P,W) = \begin{cases} - W \log(1 + \beta_i P/W) & \quad \text{if } W > 0, 1 + \beta_i P/W > 0\\ \infty & \quad \text{otherwise} \end{cases} $$ is the perspective of the convex function $$ g(x) = -\log(1 + \beta_i x). $$ (See section 3.2.6, p. 89 of Boyd and Vandenberghe.) But I need to think more carefully about whether $W$ is restricted to be positive.