source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/modules/global/addmcgormick.m @ 37

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

Added original make3d

File size: 3.1 KB
Line 
1function pcut = addmcgormick(p)
2
3pcut = p;
4
5z = p.bilinears(:,1);
6x = p.bilinears(:,2);
7y = p.bilinears(:,3);
8
9still_uncertain = find(abs(p.lb(z)-p.ub(z))>1e-8);
10if ~isempty(still_uncertain)
11
12    x_lb = p.lb(x);
13    x_ub = p.ub(x);
14    y_lb = p.lb(y);
15    y_ub = p.ub(y);
16    m = length(x);
17    one = ones(m,1);
18    general_vals =[x_lb.*y_lb one -y_lb -x_lb,x_ub.*y_ub one -y_ub -x_ub,-x_ub.*y_lb -one y_lb x_ub,-x_lb.*y_ub -one y_ub x_lb]';  %3
19    general_cols = [one z+1 x+1 y+1 one z+1  x+1 y+1 one z+1 x+1 y+1 one z+1 x+1 y+1]';
20    general_row = [1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4];
21    quadratic_row = [1;1;1;2;2 ;2; 3; 3; 3];
22
23    quadratic_cols =  [one  z+1 x+1 one z+1 x+1 one  z+1 x+1]';
24    quadratic_vals = [-x_ub.*x_lb -one x_lb+x_ub x_lb.*y_lb one -y_lb-x_lb x_ub.*y_ub one -y_ub-x_ub]';
25
26    m = 1+length(p.c);
27    rows = [];
28    cols = [];
29    vals = [];
30    nrow = 0;
31%    dummy = ismembc(p.bilinears(:,1),p.r);
32    for i =still_uncertain(:)'% 1:size(p.bilinears,1)
33        x = p.bilinears(i,2);
34        y = p.bilinears(i,3);
35        if x~=y
36            if 0%dummy(i)
37                here = find(p.bilinears(i,1) == p.r);
38                if p.s(here) > 0
39                    rows = [rows;general_row(1:8,:)+nrow];
40                    vals = [vals;general_vals(1:8,i)];
41                    cols = [cols;general_cols(1:8,i)];
42                    nrow = nrow + 2;
43                elseif p.s(here)<0
44                    rows = [rows;general_row(1:8,:)+nrow];
45                    vals = [vals;general_vals(9:end,i)];
46                    cols = [cols;general_cols(9:end,i)];
47                    nrow = nrow + 2;
48                end
49            else
50                rows = [rows;general_row+nrow];
51                vals = [vals;general_vals(:,i)];
52                cols = [cols;general_cols(:,i)];
53                nrow = nrow + 4;
54            end
55        else
56            if 0%dummy(i)
57                %col = quadratic_cols(:,i);
58                %val = quadratic_vals(:,i);
59                here = find(p.bilinears(i,1) == p.r);
60                if p.s(here) > 0
61                    rows = [rows;quadratic_row(1:6,:)+nrow];
62                    vals = [vals;quadratic_vals(4:end,i)];
63                    cols = [cols;quadratic_cols(4:end,i)];
64                    nrow = nrow + 2;
65                elseif p.s(here)<0
66                    rows = [rows;quadratic_row(1:3,:)+nrow];
67                    vals = [vals;quadratic_vals(1:3,i)];
68                    cols = [cols;quadratic_cols(1:3,i)];
69                    nrow = nrow + 1;
70                    %rows = [rows;general_row+nrow];
71                    %vals = [vals;val];
72                    %cols = [cols;col];
73                    %nrow = nrow + 4;
74                end
75            else
76                col = quadratic_cols(:,i);
77                val = quadratic_vals(:,i);
78                rows = [rows;quadratic_row+nrow];
79                vals = [vals;val];
80                cols = [cols;col];
81                nrow = nrow + 3;
82            end
83        end
84    end
85
86    F_temp = sparse(rows,cols,vals,nrow,m);
87    keep = find(~isinf(F_temp(:,1)));
88    F_temp = F_temp(keep,:);
89    pcut.F_struc = [F_temp;pcut.F_struc];
90    pcut.K.l = pcut.K.l+size(F_temp,1);
91end
92
Note: See TracBrowser for help on using the repository browser.