[37] | 1 | function varargout = implies(varargin) |
---|
| 2 | %IMPLIES Logical implication |
---|
| 3 | % |
---|
| 4 | % IMPLIES(X,Y) creates a mixed integer representation of |
---|
| 5 | % the constraint X --> Y, i.e. Y is true if X is true. |
---|
| 6 | % |
---|
| 7 | % Syntax |
---|
| 8 | % F = implies(X,Y,tol) |
---|
| 9 | % |
---|
| 10 | % Input |
---|
| 11 | % X : binary SDPVAR variable or a constraint |
---|
| 12 | % Y : binary SDPVAR variable or a constraint |
---|
| 13 | % tol: Optional threshhold for defining zero (see NOTE) |
---|
| 14 | % |
---|
| 15 | % Output |
---|
| 16 | % F : SET object |
---|
| 17 | % |
---|
| 18 | % Examples |
---|
| 19 | % |
---|
| 20 | % binvar X,Y; F = set(implies(X,Y)); |
---|
| 21 | % binvar X;sdpvar Y; F = set(implies(X,Y>5)); |
---|
| 22 | % binvar X;Y=sdpvar(3,1); F = set(implies(X,[sum(Y);Y(2)]>[5;0])); |
---|
| 23 | % |
---|
| 24 | % Note |
---|
| 25 | % Using implies with X non-binary is highly sensitive numerically. |
---|
| 26 | % The problem comes from the definition of 0 in a floating-point |
---|
| 27 | % environment, and precision in the solver. To account for this, |
---|
| 28 | % the user can supply a third argument to define a dead-zone around |
---|
| 29 | % zero, i.e Implies(X>0,Y) will be replaced with IMPLIES(abs(X)<tol,Y) |
---|
| 30 | % Note, you always need to tqweak this number for your application. By |
---|
| 31 | % default, YALMIP uses tol = 0, which means you can get garbage... |
---|
| 32 | % |
---|
| 33 | % The function IMPLIES is not complete, but will be |
---|
| 34 | % improved upon in future releases. |
---|
| 35 | % |
---|
| 36 | % See also @SDPVAR/AND, @SDPVAR/OR, IFF |
---|
| 37 | |
---|
| 38 | % Author Johan Löfberg |
---|
| 39 | % $Id: implies.m,v 1.1 2006/05/14 13:02:34 joloef Exp $ |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | % There are some cases to take care of... |
---|
| 43 | % |
---|
| 44 | % X --> Y binary/binary : Implemented |
---|
| 45 | % X --> Y binary/(LP,equality,sdp) Implemented |
---|
| 46 | % X --> Y (LP,equality,sdp)/binary Not implemented |
---|
| 47 | % X --> Y (LP,equality,sdp)/(LP,equality,sdp) Not implemented |
---|
| 48 | |
---|
| 49 | X = varargin{1}; |
---|
| 50 | Y = varargin{2}; |
---|
| 51 | |
---|
| 52 | % Call recursicely on X -> (A,B,...) |
---|
| 53 | if isa(varargin{1},'sdpvar') & (isa(varargin{2},'lmi') | isa(varargin{2},'constraint')) |
---|
| 54 | if length(varargin{1})==1 & length(varargin{2}) >1 |
---|
| 55 | F = set([]); |
---|
| 56 | for i = 1:length(varargin{2}) |
---|
| 57 | F = F + implies(varargin{1},varargin{2}(i)); |
---|
| 58 | end |
---|
| 59 | varargout{1} = F; |
---|
| 60 | return |
---|
| 61 | end |
---|
| 62 | end |
---|
| 63 | |
---|
| 64 | if nargin == 3 |
---|
| 65 | tol = varargin{3}; |
---|
| 66 | else |
---|
| 67 | tol = 0; |
---|
| 68 | end |
---|
| 69 | |
---|
| 70 | switch class(varargin{1}) |
---|
| 71 | |
---|
| 72 | case 'sdpvar' |
---|
| 73 | varargout{1} = set(yalmip('addextendedvariable',mfilename,varargin{:}) == 1); |
---|
| 74 | |
---|
| 75 | case 'char' |
---|
| 76 | varargout{1} = implies_internal(varargin{3},varargin{4}); |
---|
| 77 | varargout{2} = struct('convexity','milp','monotonicity','milp','definiteness','milp','extra','marker'); |
---|
| 78 | varargout{3} = varargin{3}; |
---|
| 79 | end |
---|
| 80 | |
---|