semivar restriction

26 views
Skip to first unread message

Bastian

unread,
May 22, 2018, 9:59:49 AM5/22/18
to YALMIP
Hello,

I'm using a semivar in my model.

inc   = semivar(1, size(matrix, 1));

constraints = [ 0.2 <=  inc <=   max ];

Is there any possibility to restrict the total number of inc values unequal zero?


I tried

constraints = [constraints,...
0 <= sum((increase ~= 0)) <= 30];

and

0 <= sum((increase >= 0.1)) <= 30];

but it always shows the error: "Undefined function 'sum' for input arguments of type 'constraint'."


I don't wanna use implies and create a binary variable for every element of inc since there are like 7000 - 25000 elements of inc in my model.


Kind regards


Johan Löfberg

unread,
May 22, 2018, 10:14:49 AM5/22/18
to YALMIP
nnz(inc) <= 30

however, this will be an unnecessarily complicated model, as you will have the combinatorial structure in semivar (eeffectively binary variables) and the binary variables used in nnz, and they will be disconnected, but really model the same thing. You should use [0.2*d <= inc <= d*maxvalue, sum(d) <= 30] where d is a binary vector.

Bastian

unread,
May 29, 2018, 11:43:24 AM5/29/18
to YALMIP
Another thought about it. Wasn't it enough to put the binary variable "d" at the left side? Like:

[0.2*d <= inc <= maxvalue, sum(d) <= 30]

Johan Löfberg

unread,
May 29, 2018, 11:52:32 AM5/29/18
to YALMIP
you want at most 30 of them to be non-zero. in your model, all of them can be maxvalue if they wish

Bastian

unread,
May 29, 2018, 12:01:11 PM5/29/18
to YALMIP
But they can only be max value when they fullfill the non-zero condition anyway or am I wrong? Is there a difference I can't see. If not, which one is the most efficient implementation?

Johan Löfberg

unread,
May 29, 2018, 12:04:01 PM5/29/18
to YALMIP
regardless of the value of d, inc=maxvalue is feasible in your wrong model

d = 0: [0 <= inc <= maxvalue] hence inc=maxvalue ok

d = 1: [.2 <= inc <= maxvalue] hence inc=maxvalue ok

Bastian

unread,
May 29, 2018, 12:10:56 PM5/29/18
to YALMIP
Ah I've got it. Thank you!
Reply all
Reply to author
Forward
0 new messages