sum of logical constraints using sdpvar

37 views
Skip to first unread message

Hongkai Chen

unread,
Sep 11, 2018, 11:58:33 AM9/11/18
to YALMIP
Hi Johan,

If I have a sdpvar of length 10. If we want a constraint stating that the number of decreases followed by an increase is less than 2. How do I write it?

The pseudo code is like

a = sdpvar(10,1);
sum(a(i)>=0 & a(i+1)<0) <=2, for i =1,2...9

Johan Löfberg

unread,
Sep 11, 2018, 3:04:18 PM9/11/18
to yal...@googlegroups.com
You would have to introduce indicators etc to trigger various cases. One model I guess would be something like this

a = sdpvar(20,1);
pos = binvar(20,1);
neg = binvar(20,1);
Model = [pos + neg == 1, implies(a>=0,pos) + implies(a <= 0,neg), -100 <= a <= 100];
y = randn(20,1);
objective = (a-y)'*(a-y);
Model = [Model, sum(max(diff(neg),0)) <= 2];
optimize(Model,objective)
[value(pos) value(neg) value(a)]

note that the problem / model is ill-posed around zero (as you cannot have strict inequalities)
Reply all
Reply to author
Forward
0 new messages