How to model this constraint in CVX?


D is a variable, of size C\times U
P is also a variable of size NC\times U

I have a constraint as below:

if D(c,u)=1, P((c-1)*N+1,u)=((c-1)*N+2,u)=\cdots =P(c*N,u)\le T
if D(c,u)=0, P((c-1)*N+1:c*N,u)= 0

For example, for c=2,u=1, if D(c,u)=1 then
P(17,1)=P(18,1)=\cdots=P(32,1)=x where 0<x\le T

I was trying the following

      for c=1:C
           for u=1:U
                P((c-1)*N+1:c*N,u) <= D(u,c)*T;
                P((c-1)*N+1:c*N,u) >= 0;

But I don’t think it does what I want.

Any help?

You should first help your self by having a consistent problem statement and code.

presume T = sqrt(P_max). And why do you have P(17,1)=P(18,1)=⋯=P(32,1)=x, i don’t see that in the constraint you stated, so I will presume there is no such constraint. In that case, and presuming 0 is a lower bound for P, your code seems to correspond to the constraint you stated. if you think it doesn’t, you need to explain why.

Perhaps the first constraint in your code can be vectorized using the techniques in How to vectorize most constraint loops in CVX , but vextorization is not necessary if the CVX constraint building process is fast enough for you. In any event, I’ll leave that to others to address. I believe the second constraint in your code can be removed from the for loops and stated simply as P >= 0, or declaring P as nonnegative.

If my assumptions are not correct, you will need to clarify.

I have updated my question. Sorry for the confusion.

It sounds like regardless of the value of D(c,u), you want P((c−1)∗N+1,u)=((c−1)∗N+2,u)=⋯=P(c∗N,u). Therefore, either introduce an appropriate (vector or matrix) variable x, or an expression x, which achieves that by construction, and use that instead of P(...) in the first constraint. I’ll let you work out the indexing. As with my previous post, you easily can move x >= 0 out of the for loops.

No, it is not regardless of D(c,u). If D(c,u)=1, then P((c−1)∗N+1,u)=((c−1)∗N+2,u)=⋯=P(c∗N,u)>0. and when D(c,u)=0, then P((c−1)∗N+1,u)=((c−1)∗N+2,u)=⋯=P(c∗N,u)==0.

I’ll leave this to someone else who perhaps can understand your problem, because I don’t.