source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/extras/@ncvar/or.m @ 37

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

Added original make3d

File size: 2.4 KB
Line 
1function varargout = or(varargin)
2%OR (overloaded)
3%   
4%    z = or(x,y)
5%    z = x | y
6%
7% The OR operator is implemented using the concept of nonlinear operators
8% in YALMIP. X|Y defines a new so called derived variable that can be
9% treated as any other variable in YALMIP. When SOLVESDP is issued,
10% constraints are added to the problem to model the OR operator. The new
11% constraints add constraints to ensure that z,x and y satisfy the
12% truth-table for OR.
13%
14% The model for OR is set(z>x) + set(z>y) + set(z<x+y) + set(binary(z))
15%
16% It is assumed that x and y are binary variables (either explicitely
17% declared using BINVAR, or constrained using BINARY.)
18%
19%   See also SDPVAR/AND, BINVAR, BINARY
20
21% Author Johan Löfberg
22% $Id: or.m,v 1.1 2006/08/10 18:00:21 joloef Exp $   
23
24% Author Johan Löfberg
25% $Id: or.m,v 1.1 2006/08/10 18:00:21 joloef Exp $   
26
27% Models OR using a nonlinear operator definition
28switch class(varargin{1})
29    case 'char'
30        z = varargin{2};
31        x = varargin{3};
32        y = varargin{4};       
33         
34        % *******************************************************
35        % For *some* efficiency,we merge expressions like A|B|C|D
36        xvars = getvariables(x);
37        yvars = getvariables(y);
38        allextvars = yalmip('extvariables');
39       
40        if (length(xvars)==1) & ismembc(xvars,allextvars)
41            x = expandor(x,allextvars);
42        end
43       
44        if (length(yvars)==1) & ismembc(yvars,allextvars)
45            y = expandor(y,allextvars);
46        end
47        % *******************************************************
48                 
49        xy=[x y];
50       
51        varargout{1} = set(sum(xy) > z) + set(z > xy) +set(binary(z)) ;
52        varargout{2} = struct('convexity','milp','monotonicity','milp','definiteness','milp');
53        varargout{3} = xy;
54
55    case 'sdpvar'
56        x = varargin{1};
57        y = varargin{2};
58        varargout{1} = yalmip('addextendedvariable','or',varargin{:});
59
60    otherwise
61end
62
63function x = expandor(x,allextvars)
64
65xmodel = yalmip('extstruct',getvariables(x));
66
67if isequal(xmodel.fcn,'or')
68    x1 = xmodel.arg{1};
69    x2 = xmodel.arg{2};
70    if  ismembc(getvariables(xmodel.arg{1}),allextvars)
71        x1 = expandor(xmodel.arg{1},allextvars);     
72    end
73    if  ismembc(getvariables(xmodel.arg{2}),allextvars)
74        x2 = expandor(xmodel.arg{2},allextvars);     
75    end
76    x = [x1 x2];
77end
Note: See TracBrowser for help on using the repository browser.