source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/operators/implies_internal.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 4.2 KB
Line 
1function varargout = implies_internal(varargin)
2
3% Call recursicely on X -> (A,B,...)
4if isa(varargin{1},'sdpvar') & isa(varargin{2},'lmi')
5    if length(varargin{1})==1 & length(varargin{2}) >1
6        F = set([]);
7        for i = 1:length(varargin{2})
8            F = F + implies_internal(varargin{1},varargin{2}(i));
9        end
10        varargout{1} = F;
11        return
12    end
13end
14
15X = varargin{1};
16Y = varargin{2};
17
18switch class(X)
19
20    case 'sdpvar'
21
22        switch class(Y)
23
24            case 'sdpvar'              % X --> Y
25                varargout{1} = set(Y >= X);
26
27            case {'lmi','constraint'}
28                if isa(Y,'constraint')
29                    Y = set(Y,[],[],1);
30                end
31                switch settype(Y)
32
33                    case 'elementwise' % X --> (Y(:)>=0)
34                        Y = sdpvar(Y);
35                        [M,m,infbound]=derivebounds(Y);
36                        if infbound
37                            warning('You have unbounded variables in IMPLIES leading to a lousy big-M relaxation.');
38                        end
39                        %varargout{1} = set(Y >= (1-X).*m);
40                        varargout{1} = set(Y - (1-X).*m);
41
42                    case 'equality'    % X --> (Y(:)==0)
43                        Y = sdpvar(Y);
44                        [M,m,infbound]=derivebounds(Y);
45                        if infbound
46                            warning('You have unbounded variables in IMPLIES leading to a lousy big-M relaxation.');
47                        end
48                        % varargout{1} = set((1-X).*M >= Y) + set(Y >= (1-X).*m);
49                        % Better display and somewhat faster
50                        temp = 1-X;
51                        varargout{1} = set([temp.*M - Y;Y - temp.*m]);
52
53                    case 'sdp'         % X --> (Y>=0)
54                        if length(X)>1
55                            error('IMPLIES not implemented for this case.');
56                        end
57                        Y = sdpvar(Y);
58                        % Elements in matrix
59                        y = Y(find(triu(ones(length(Y)))));
60                        % Derive bounds on all elements
61                        [M,m,infbound]=derivebounds(y);
62                        if infbound
63                            warning('You have unbounded variables in IMPLIES leading to a lousy big-M relaxation.');
64                        end
65                        % Crude lower bound eig(Y) > -max(abs(Y(:))*n*I
66                        m=-max(abs([M;m]))*length(Y);
67                        % Big-M relaxation...
68                        varargout{1} = set(Y >= (1-X)*m*eye(length(Y)));
69
70                    otherwise
71                        error('IMPLIES not implemented for this case');
72                end
73            otherwise
74                error('IMPLIES not implemented for this case');
75        end
76
77    case {'lmi','constraint'}
78        if isa(X,'constraint')
79            X = set(X,[],[],1);
80        end
81        if isa(Y,'constraint')
82            Y = set(Y,[],[],1);
83        end
84        if length(Y) == 1
85            if isa(Y,'sdpvar') | isequal(settype(Y),'elementwise')
86                Y = sdpvar(Y);
87                switch settype(X)
88                    case 'elementwise'
89                        X = sdpvar(X);X=X(:);
90                        [Mx,mx,infbound]=derivebounds(X);
91                        if infbound
92                            warning('You have unbounded variables in IMPLIES leading to a lousy big-M relaxation.');
93                        end
94                        di = binvar(length(X),1);
95                        if is(Y,'binary')
96                            varargout{1} = set(X <= tol + Mx.*di) + set(Y>=0.5*(sum(di)-length(di)+1));
97                        else
98                            [My,my]=derivebounds(Y);
99                            varargout{1} = set(X <= tol + Mx.*di) + set(Y>=my*(1-(sum(di)-length(di)+1)));
100                        end
101
102                    otherwise
103                        error('IMPLIES not implemented for this case');
104                end
105
106            else
107                error('IMPLIES not implemented for this case');
108            end
109        end
110    otherwise
111        error('IMPLIES not implemented for this case');
112end
113
Note: See TracBrowser for help on using the repository browser.