source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/operators/semivar.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 = semivar(varargin)
2%SEMIVAR Create symbolic semicontinuous variable
3%
4%   SEMIVAR works exactly as SDPVAR, with the only difference that
5%   the elements in the variable automatically will be constrained
6%   to be semicontinous (x = 0 or |x| > 1)
7%
8%   See also SDPVAR, BINVAR, INTVAR, BINARY, INTEGER
9
10% Author Johan Löfberg
11% $Id: semivar.m,v 1.2 2006/06/07 09:24:14 joloef Exp $
12
13if isa(varargin{1},'char')
14    switch varargin{1}
15        case {'graph','milp'}
16            t = varargin{2};
17            d = binvar(3,1);
18            [M,m] = derivebounds(t);
19            % Zero case
20            F = set(m.*(1-d(3)) < t < M.*(1-d(3)));
21            % Special cases to speed up integer solve
22            if M <=0
23                F = F + set(t < -1+(M+1)*(1-d(2)));
24                F = F + set(d(3) + d(2)==1);               
25            elseif m>=0
26                F = set(t >= 1+(1-d(1))*(m-1));
27                F = F + set(d(3) + d(1)==1);               
28            else
29                F = set(t >= 1+(1-d(1))*(m-1)) + set(t < -1+(M+1)*(1-d(2)));
30                F = F + set(m.*(1-d(3)) < t < M.*(1-d(3)));
31                F = F + set(sum(d)==1);               
32            end
33            varargout{1} = F;
34            varargout{2} = struct('convexity','milp','monotonicity','milp','definiteness','milp');
35            varargout{3} = 1;
36            return
37        otherwise
38            % Command line creation
39            all_variable_names = 1;
40            i = 1;
41            while all_variable_names & i<=nargin
42                all_variable_names = all_variable_names & isvarname(varargin{i});
43                i = i + 1;
44            end
45            if all_variable_names
46                for k = 1:nargin
47                    varname = varargin{k};
48                    assignin('caller',varname,semicont(1,1));
49                end
50                return
51            end
52    end
53end
54
55% Create dummy SDPVAR object
56sys = sdpvar(varargin{:});
57n = length(getvariables(sys));
58% Create new variables
59y = [];
60for i = 1:n
61    y = [y;yalmip('addextendedvariable',mfilename,rand)];
62end
63%  Replace variables to the semicontinous variables
64varargout{1} = reshape(getbase(sys)*[1;y],size(sys,1),size(sys,2));
Note: See TracBrowser for help on using the repository browser.