2
$\begingroup$

I am trying to implement the objective function max a . x + c . abs(x - g). where all elements of c are non-positive, x are the decision variables, and a and g are just any vector parameters.

Given I need to repeatedly solve the problem, I am trying to use a DPP formulation in CVXPY. However, this fails (I believe because both c and g are parameters, so this is taking a product of parameters). Sample code:

import cvxpy as cp
n_vars = 3
x = cp.Variable(shape=(n_vars,))
c = cp.Parameter(shape=(n_vars,), nonpos=True)
g = cp.Parameter(shape=(n_vars,))
penalization_term = c @ cp.abs(x - g)
print(f"Penalization term is: 1) DCP: {penalization_term.is_dcp()} 2) DPP: {penalization_term.is_dcp(dpp=True)}")

Output: Penalization term is: 1) DCP: True 2) DPP: False

Is there a way to reformulate the problem for it to be DPP (Disciplined Parameter Programming)?

$\endgroup$

1 Answer 1

2
$\begingroup$

The solution occurred to me as I was writing this... In case helpful, here it is:

import cvxpy as cp
n_vars = 3
x = cp.Variable(shape=(n_vars,))
c = cp.Parameter(shape=(n_vars,), nonpos=True)
a = cp.Parameter(shape=(n_vars,))
g = cp.Parameter(shape=(n_vars,))
g_var = cp.Variable(shape=(n_vars,))
penalization_term = c @ cp.abs(x - g_var)
prob = cp.Problem(cp.Maximize(a @ x + penalization_term), [g_var == g])
print(f"Penalization term is: 1) DCP: {penalization_term.is_dcp()} 2) DPP: {penalization_term.is_dcp(dpp=True)}")
print(f"Problem is: 1) DCP: {prob.is_dcp()}, 2) DPP: {prob.is_dcp(dpp=True)}")
$\endgroup$
1
  • 1
    $\begingroup$ This is basically the same (introducing a new variable and a linear equality constraint on that) as the 1st reformulation shown at cvxpy.org/tutorial/dpp/index.html . $\endgroup$ Commented Jun 18 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.