Is it possible to convert non-zero values to one in CVX?

Hi,

I am working on a model likes:

expression a(N);
variable p(N);
variable b(N)
obj = obj + b * Constant;
min(obj);

subject to
for i = 1:N
    b(i)>= a(i);
    b(i)<= a(i);
end

where the value of expression a depends on a step function of the variable p :
a(i) = 0, if p(i)=0
a(i) = 1, if p(i)>0

I have studied the materials on the website of CVX, but still have no idea how to implement a constraint like the above equation. Is it possible to implement such constraints in cvx?

Thank you!

You need to use Big M logic modeling. You will need to declare a as a binary variable rather than an expression.

I presume p is nonnegative, although you haven’t declared it as such or specified such a constraint. The constraint below will enforce nonnegativity of p. Assume U is an upper bound for p (U could be a scalar or a vector).

Let non-zero_threshold be a small positive number, such as 1e-5, for what constitutes the smallest value of p which is practically speaking positive (keep in mind solver tolerances might allow a variable value of 1e-8 when it is really essentially zero).

non-zero_threshold*a <= p <= U.*a

Hi Mark,
Thanks for the quick response! The big M modeling does work, but seems a will be set to a small number because of p might get small compared to its upper bound. I specify it as binary and use Mosek to solve the problem. I am also considering using Taylor Series Approximation and penalized the objective function to make it an binary variable.

Is there any better approach to address this problem?

Thank you!

As I wrote, declare a as binary. Then use a solver, such as Mosek, which can handle binary variables. That should be better than trying to create a penalty term or use a Taylor series approximation. I think Mosek or Gurobi will do a better job of handling binary variables than any "home-brew’ approach you might create.

Got that! Thank you so much, Mark!