⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 implies.m

📁 国外专家做的求解LMI鲁棒控制的工具箱,可以相对高效的解决LMI问题
💻 M
字号:
function varargout = implies(varargin)
%IMPLIES Logical implication
%
% IMPLIES(X,Y) creates a mixed integer representation of
% the constraint X --> Y, i.e. Y is true if X is true.
%
% Syntax
%   F = implies(X,Y)
%
% Input
%   X : binary SDPVAR variable or a constraint
%   Y : binary SDPVAR variable or a constraint
%
% Output
%   F : SET object
%
% Examples
%
%  binvar X,Y; F = set(implies(X,Y));
%  binvar X;sdpvar Y; F = set(implies(X,Y>5));
%  binvar X;Y=sdpvar(3,1); F = set(implies(X,[sum(Y);Y(2)]>[5;0]));
%
% Note
%  The function IMPLIES is not complete, but will be
%  improved upon in future releases.
%
%   See also @SDPVAR/AND, @SDPVAR/OR, IFF

% Author Johan L鰂berg
% $Id: implies.m,v 1.11 2005/06/22 16:45:14 joloef Exp $


% There are some cases to take care of...
%
% X --> Y     binary/binary :                     Implemented
% X --> Y     binary/(LP,equality,sdp)            Implemented
% X --> Y     (LP,equality,sdp)/binary            Not implemented
% X --> Y     (LP,equality,sdp)/(LP,equality,sdp) Not implemented

X = varargin{1};
Y = varargin{2};
switch class(varargin{1})

    case 'sdpvar'

        if length(X)>1
            error('IMPLIES not implemented for this case.');
        end

        switch class(Y)

            case 'sdpvar'              % X --> Y
                varargout{1} = set(Y >= X);

            case {'lmi','constraint'}
                Y = set(Y,[],[],1);
                switch settype(Y)

                    case 'elementwise' % X --> (Y(:)>=0)
                        Y = sdpvar(Y);
                        [M,m]=derivebounds(Y);
                        varargout{1} = set(Y >= (1-X)*m);

                    case 'equality'    % X --> (Y(:)==0)
                        Y = sdpvar(Y);
                        [M,m]=derivebounds(Y);
                        varargout{1} = set((1-X)*M >= Y >= (1-X)*m);

                    case 'sdp'         % X --> (Y>=0)
                        Y = sdpvar(Y);
                        % Elements in matrix
                        y = Y(find(triu(ones(length(Y)))));
                        % Derive bounds on all elements
                        [M,m]=derivebounds(y);
                        % Crude lower bound eig(Y) > -max(abs(Y(:))*n*I
                        m=-max(abs([M;m]))*length(Y);
                        % Big-M relaxation...
                        varargout{1} = set(Y >= (1-X)*m*eye(length(Y)));

                    otherwise
                        error('IMPLIES not implemented for this case');
                end
            otherwise
                error('IMPLIES not implemented for this case');
        end

    case {'lmi','constraint'}
        X = set(X,[],[],1);
        switch class(Y)
            case 'sdpvar'
                switch settype(X)
                    case 'elementwise'
                        X = sdpvar(X);X=X(:);
                        [M,m]=derivebounds(X);
                        if length(X)>1
                            di = binvar(length(X),1);
                            varargout{1} = set(X <= M.*di) + set(Y>=sum(di)-length(di)+1);
                        else
                            varargout{1} = set(X <= M*Y);
                        end
                    case 'equality'
                        X = sdpvar(X);X=X(:);
                        [M,m]=derivebounds(X);
                        if length(X)>1
                            di = binvar(length(X),1);
                            varargout{1} = set(m.*di <= X <= M.*di) + set(Y>=sum(di)-length(di)+1);
                        else
                            varargout{1} = set(m*Y <= X <= M*Y);
                        end

                    otherwise
                        error('IMPLIES not implemented for this case');
                end

            otherwise
                error('IMPLIES not implemented for this case');
        end
    otherwise
        error('IMPLIES not implemented for this case');
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -