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

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

Added original make3d

File size: 3.5 KB
Line 
1function pen = sedumi2pen(F_struc,K,c,x0)
2%SEDUMI2MPEN Internal function to convert SeDuMi structure to format needed in PENNON
3
4% Author Johan Löfberg
5% $Id: sedumi2pen.m,v 1.15 2006/08/24 17:12:27 joloef Exp $
6
7% General data
8pen.vars = length(c);
9pen.constr = K.l;
10if length(K.s)>1
11    pen.mconstr = length(K.s);
12else
13    if K.s==0
14        pen.mconstr=0;
15    else
16        pen.mconstr=1;
17    end
18end
19pen.msizes = K.s;
20pen.fobj = c(:)';
21pen.x0 = zeros(1,length(c));
22
23% Linear constraints
24if K.l>0
25    pen.ci = full(F_struc(K.f+1:K.f+K.l,1))';
26    pen.bi_dim = zeros(1,K.f+K.l);
27    [variables,constr,val] = find(-F_struc(1:K.l,2:end)');
28    pen.bi_idx = variables(:)'-1;
29    pen.bi_val = val(:)';
30    j = 1;
31
32    if ~isempty(constr)
33        rr = histc(constr,[1:max(constr)]);
34        uu = find(rr);
35        pen.bi_dim(uu) = rr(uu);
36        %uns = uniquestripped(constr);
37        %for j = 1:length(uns)
38        %    pen.bi_dim(uns(j)) = sum(constr==uns(j));
39        %end
40    end
41
42else
43    pen.ci = 0;
44    pen.bi_dim = 0;
45    pen.bi_idx = 0;
46    pen.bi_val = 0;
47end
48
49% Semidefnite constraints
50if K.s>0
51    top = K.l+K.f+1;
52    constraints = 1;
53    pen.ai_dim = zeros(1,length(K.s));
54
55    % First, optimized code for scalar SDPs (happens for nonlinear scalar constraints)
56    if all(K.s==1)
57
58        Avec = -F_struc(top:top+length(K.s)-1,:);
59        [variables,constr,val] = find(Avec');
60        j = 1;
61        n_nz = length(val);
62        pen.ai_nzs = repmat(1,1,n_nz);
63        pen.ai_row = repmat(0,1,n_nz);
64        pen.ai_col = pen.ai_row;%repmat(0,1,n_nz);
65        pen.ai_val = val(:)';
66        pen.ai_idx = variables(:)'-1;
67        while j<=length(val)
68            first_constraint = constr(j);
69            n_nz = 1;
70            while j+n_nz<=length(val) & constr(j+n_nz)==first_constraint
71                n_nz = n_nz + 1;
72            end
73            pen.ai_dim(first_constraint) = n_nz;
74            j = j + n_nz;
75        end
76    else
77        pen.ai_idx = [];
78        pen.ai_val = [];
79        pen.ai_row = [];
80        pen.ai_col = [];
81        pen.ai_nzs = [];       
82        while (constraints<=length(K.s))
83            n = K.s(constraints);           
84            Avec = -F_struc(top:top+n^2-1,:);
85            picker = reshape(1:n^2,n,n);picker = tril(picker-diag(diag(picker)));picker = find(picker(:));           
86            [rowcols,varindicies,vals]=find(Avec);
87            %the_col = 1+floor((rowcols-1)/n);
88            %the_row = rowcols-(the_col-1)*n;
89            %removethese = the_row > the_col;
90            removethese = find(ismembc(rowcols,picker));
91            rowcols(removethese) =[];
92            varindicies(removethese)=[];
93            vals(removethese)=[];
94            if ~isempty(rowcols)
95                cols = ceil(rowcols/n);
96                rows = rowcols - n*(cols-1);
97                uns = uniquestripped(varindicies);
98               
99                difference = diff([varindicies(:) ; max(varindicies)+1]);
100                count = diff(find([1 ; difference]))';
101                pen.ai_nzs = [pen.ai_nzs count];
102                               
103                pen.ai_dim(constraints) =  length(uniquestripped(varindicies));
104                pen.ai_idx = [pen.ai_idx uns(:)'-1];
105                pen.ai_row = [pen.ai_row rows(:)'-1];
106                pen.ai_col = [pen.ai_col cols(:)'-1];
107                pen.ai_val = [pen.ai_val vals(:)'];
108            end
109            constraints = constraints+1;
110            top = top+n*n;
111        end
112    end
113else
114    pen.ai_dim = 0;
115    pen.ai_idx = 0;
116    pen.ai_val = 0;
117    pen.ai_row = 0;
118    pen.ai_col = 0;
119    pen.ai_nzs = 0;
120end
Note: See TracBrowser for help on using the repository browser.