1 | function varargout = iff(varargin) |
---|
2 | %IFF Logical equivalence |
---|
3 | % |
---|
4 | % IFF(X,Y) creates a mixed integer representation of |
---|
5 | % the constraint X <--> Y, i.e. Y is true iff X is true. |
---|
6 | % |
---|
7 | % Syntax |
---|
8 | % F = iff(X,Y) |
---|
9 | % |
---|
10 | % Input |
---|
11 | % X : binary SDPVAR variable or a constraint |
---|
12 | % Y : binary SDPVAR variable or a constraint |
---|
13 | % |
---|
14 | % Output |
---|
15 | % F : SET object |
---|
16 | % |
---|
17 | % Examples |
---|
18 | % |
---|
19 | % binvar X,Y; F = set(iff(X,Y)); |
---|
20 | % sdpvar X;binvar Y; F = set(iff(X>5,Y)); |
---|
21 | % sdpvar X;binvar Y; F = set(iff(Y,X==5)); |
---|
22 | % |
---|
23 | % Overloading |
---|
24 | % |
---|
25 | % The iff overloads == for logic constraints. |
---|
26 | % |
---|
27 | % sdpvar X;binvar Y; F = set((X>5) == Y); |
---|
28 | % sdpvar X;binvar Y; F = set(Y == (X==5)); |
---|
29 | |
---|
30 | % |
---|
31 | % Note |
---|
32 | % The function IFF is not complete, but will be |
---|
33 | % improved upon in future releases. |
---|
34 | % |
---|
35 | % See also @SDPVAR/AND, @SDPVAR/OR, IMPLIES |
---|
36 | |
---|
37 | % Author Johan Löfberg |
---|
38 | % $Id: iff.m,v 1.2 2006/05/16 07:59:23 joloef Exp $ |
---|
39 | |
---|
40 | % There are some cases to take care of... |
---|
41 | % X <--> Y binary/binary |
---|
42 | % X <--> Y binary/(lp,equality) |
---|
43 | % X <--> Y (lp,equality)/binary |
---|
44 | % X <--> Y (lp,equality)/(lp,equality) |
---|
45 | |
---|
46 | X = varargin{1}; |
---|
47 | Y = varargin{2}; |
---|
48 | |
---|
49 | switch class(varargin{1}) |
---|
50 | case {'constraint','sdpvar'} |
---|
51 | varargout{1} = set(yalmip('addextendedvariable',mfilename,varargin{:}) == 1); |
---|
52 | |
---|
53 | case 'char' |
---|
54 | varargout{1} = iff_internal(varargin{3},varargin{4}); |
---|
55 | varargout{2} = struct('convexity','milp','monotonicity','milp','definiteness','milp','extra','marker'); |
---|
56 | varargout{3} = varargin{3}; |
---|
57 | end |
---|
58 | |
---|