I am trying to formulate a convex optimization problem using CVXPY. Everything works, except a constraint that does not seem to follow DCP rules.
Let $D \in \Bbb R^n$ be a decision variable and let $Q$ be another decision variable that is derived from $D$ using the following constraint,
Q = cvxpy.pos(D)
I am not sure why this is the case. Here it states that pos
is a convex atom.
$$ \mbox{pos} (x) := \max \{ x, 0 \} $$
Can someone please help me?
Edit:
Error message:
cvxpy.error.DCPError: Problem does not follow DCP rules. Specifically: The following constraints are not DCP: var1 == maximum(var0, 0.0) , because the following subexpressions are not: |-- var1 == maximum(var0, 0.0)
Minimum working example (if the 2nd constraint is switched off the program works),
import cvxpy as cp
import numpy as np
D = cp.Variable(2)
A = np.array([[1, 2], [2, 1]])
b = np.ones((2, )) * 2
Q = cp.Variable(2)
constraints = [sum(D) == 1, Q == cp.pos(D)]
prob = cp.Problem(cp.Minimize(cp.sum_squares(A @ D - b)), constraints)
prob.solve(verbose=True)