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

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

Added original make3d

File size: 2.2 KB
Line 
1function varargout = and(varargin)
2%ANd (overloaded)
3%   
4%    z = and(x,y)
5%    z = x & y
6%
7% The AND 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 AND operator. The new
11% constraints add constraints to ensure that z, x and y satisfy the
12% truth-table for AND.
13%
14% The model for ARE is set(z<=x)+set(z<=y)+set(1+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: and.m,v 1.1 2006/08/10 18:00:19 joloef Exp $   
23
24switch class(varargin{1})
25    case 'char'
26        z = varargin{2};
27        x = varargin{3};
28        y = varargin{4};
29   
30        % *******************************************************
31        % For *some* efficiency,we merge expressions like A&B&C&D
32        xvars = getvariables(x);
33        yvars = getvariables(y);
34        allextvars = yalmip('extvariables');
35       
36        if (length(xvars)==1) & ismembc(xvars,allextvars)
37            x = expandand(x,allextvars);
38        end
39       
40        if (length(yvars)==1) & ismembc(yvars,allextvars)
41            y = expandand(y,allextvars);
42        end
43        % *******************************************************
44               
45        varargout{1} = set(x >= z) + set(y >= z) + set(length(x)+length(y)-1+z >= sum(x)+sum(y)) + set(binary(z));
46        varargout{2} = struct('convexity','milp','monotoncity','milp','definiteness','milp');
47        varargout{3} = [];
48
49    case 'sdpvar'
50        x = varargin{1};
51        y = varargin{2};
52
53        varargout{1} = yalmip('addextendedvariable','and',varargin{:});
54
55    otherwise
56end
57
58function x = expandand(x,allextvars)
59
60xmodel = yalmip('extstruct',getvariables(x));
61
62if isequal(xmodel.fcn,'and')
63    x1 = xmodel.arg{1};
64    x2 = xmodel.arg{2};
65    if  ismembc(getvariables(xmodel.arg{1}),allextvars)
66        x1 = expandand(xmodel.arg{1},allextvars);     
67    end
68    if  ismembc(getvariables(xmodel.arg{2}),allextvars)
69        x2 = expandand(xmodel.arg{2},allextvars);     
70    end
71    x = [x1 x2];
72end
Note: See TracBrowser for help on using the repository browser.