[37] | 1 | function varargout = ismember(varargin) |
---|
| 2 | %ISMEMBER Define membership constraint on SDPVAR object |
---|
| 3 | % |
---|
| 4 | % F = ISMEMBER(x,P) |
---|
| 5 | % |
---|
| 6 | % Input |
---|
| 7 | % x : SDPVAR object |
---|
| 8 | % P : MPT polytope object or double |
---|
| 9 | % Output |
---|
| 10 | % F : SET object |
---|
| 11 | % |
---|
| 12 | % Depending on the second argument P, different classes of constraint are |
---|
| 13 | % generated. |
---|
| 14 | % |
---|
| 15 | % If P is a single polytope, the linear constraints [H,K] = double(P); |
---|
| 16 | % F=set(H*x <= K) will be created. |
---|
| 17 | % |
---|
| 18 | % If P is a polytope array, then length(P) binary variables will be |
---|
| 19 | % introduced and the constraint will model that x is inside at least one of |
---|
| 20 | % the polytopes. |
---|
| 21 | % |
---|
| 22 | % If P is a DOUBLE, a constraint constraining the elements of x to take one |
---|
| 23 | % of the values in P is created. This will introduce numel(P)*numel(x) |
---|
| 24 | % binary variables |
---|
| 25 | % |
---|
| 26 | % Since the two last constructions are based on big-M formulations, all |
---|
| 27 | % involved variable should have explicit variable bounds. |
---|
| 28 | |
---|
| 29 | % Author Johan Löfberg |
---|
| 30 | % $Id: ismember.m,v 1.14 2006/07/26 20:17:58 joloef Exp $ |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | x = varargin{1}; |
---|
| 34 | p = varargin{2}; |
---|
| 35 | |
---|
| 36 | % Backwards compatibility (this should really be done in another command) |
---|
| 37 | % This code is probably only used in solvemoment |
---|
| 38 | if isa(x,'double') |
---|
| 39 | varargout{1} = any(full(p.basis(:,1))); |
---|
| 40 | return |
---|
| 41 | end |
---|
| 42 | |
---|
| 43 | if isa(x,'sdpvar') & isa(p,'sdpvar') |
---|
| 44 | x_base = x.basis; |
---|
| 45 | x_vars = x.lmi_variables; |
---|
| 46 | |
---|
| 47 | p_base = x.basis; |
---|
| 48 | p_vars = x.lmi_variables; |
---|
| 49 | |
---|
| 50 | % Member at all |
---|
| 51 | varargout{1} = ismember(x.lmi_variables,p.lmi_variables); |
---|
| 52 | if varargout{1} |
---|
| 53 | index_in_x_vars = find(x.lmi_variables == p.lmi_variables); |
---|
| 54 | varargout{1} = full(any(p.basis(:,1+index_in_x_vars),2)); |
---|
| 55 | if min(p.dim(1),p.dim(2))~=1 |
---|
| 56 | varargout{1} = reshape(YESNO,p.dim(1),p.dim(2)); |
---|
| 57 | end |
---|
| 58 | end |
---|
| 59 | return |
---|
| 60 | end |
---|
| 61 | |
---|
| 62 | % Here is the real overloaded ismember |
---|
| 63 | switch class(varargin{1}) |
---|
| 64 | case 'sdpvar' |
---|
| 65 | varargout{1} = set(yalmip('addextendedvariable',mfilename,varargin{:}) == 1); |
---|
| 66 | |
---|
| 67 | case 'char' |
---|
| 68 | varargout{1} = ismember_internal(varargin{3},varargin{4}); |
---|
| 69 | varargout{2} = struct('convexity','milp','monotonicity','milp','definiteness','positive','extra','marker'); |
---|
| 70 | varargout{3} = varargin{3}; |
---|
| 71 | end |
---|