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

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

Added original make3d

File size: 1.3 KB
Line 
1function varargout=alldifferent(varargin)
2
3switch class(varargin{1})
4
5    case 'double'
6        x = varargin{1};
7        x = sort(x(:));
8        varargout{1} = all(diff(x) > 0);
9
10    case 'sdpvar'
11        varargout{1} = set(yalmip('addextendedvariable',mfilename,varargin{:}) == 1);
12
13    case 'char'
14        x = varargin{3};
15        [nx,mx] = size(x);
16        x = reshape(x,nx*mx,1);
17       
18        [M,m] = derivebounds(x);
19        if 0 & all(M(1) == M) & all(m(1) == m) & (nx*mx == (M(1)-m(1) + 1))
20            % No benefit seen in this model in this special case so we
21            % don't use it to (reduce possibility of introducing a new bug)
22            d = binvar(nx*mx,nx*mx,'full');
23            F = set(d*(m(1):M(1))' == x) + set(sum(d,1) == 1) + set(sum(d,2) == 1);
24        else
25            % Add constraint |x(i)-x(j)| > 1
26            pairs = nchoosek(1:nx*mx,2);
27            d = binvar(length(pairs),1);
28            x1 = x(pairs(:,1));
29            x2 = x(pairs(:,2));
30
31            F = set(x1 - x2 > 1-(1+M(pairs(:,1))-m(pairs(:,2))).*d);
32            F = F + set(x2 - x1 > 1-(1+M(pairs(:,2))-m(pairs(:,1))).*(1-d));
33        end
34        varargout{1} = F;
35        varargout{2} = struct('convexity','milp','monotonicity','milp','definiteness','milp','extra','marker');
36        varargout{3} = varargin{3};
37end
Note: See TracBrowser for help on using the repository browser.