source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/solvers/callsdplr.m @ 37

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

Added original make3d

File size: 5.3 KB
Line 
1function output = callsdplr(interfacedata)
2
3% Author Johan Löfberg
4% $Id: callsdplr.m,v 1.8 2005/12/15 13:21:16 joloef Exp $
5
6% Retrieve needed data
7options = interfacedata.options;
8F_struc = interfacedata.F_struc;
9c       = interfacedata.c;
10K       = interfacedata.K;
11ub      = interfacedata.ub;
12lb      = interfacedata.lb;
13lowrankdetails =  interfacedata.lowrankdetails;
14
15% Create the parameter structure
16pars = options.sdplr;
17pars.printlevel = options.verbose;
18
19% *********************************************
20% Bounded variables converted to constraints
21% N.B. Only happens when caller is BNB
22% *********************************************
23if ~isempty(ub)
24    [F_struc,K] = addbounds(F_struc,K,ub,lb);
25end
26
27% rmfield is slow...
28Knew.l = K.l;
29Knew.s = K.s;
30K = Knew;
31
32if options.savedebug
33    save sdplrdebug F_struc c K pars -V6
34end
35
36% *********************************************
37%FIND LOW RANK STRUCTURES
38% *********************************************
39problem = 0;
40lrA = [];
41if ~isempty(lowrankdetails) | (options.sdplr.maxrank>0 & (K.s(1)>0))
42    showprogress('Detecting low rank data',options.showprogress);
43    sdploc = K.l+cumsum([1 K.s.^2]);
44    k = 1;
45    % FIX : Lazy code copy...
46    [ix,jx,sx] = find(F_struc);
47    if isempty(lowrankdetails)
48        % Okay, this means we have to go through everything...
49        % Get all data in F_struc for later
50        for lmiid = 1:length(K.s)
51            removethese = zeros(1,size(F_struc,2)-1);
52            for i = 1:size(F_struc,2)-1
53                Fi = reshape(F_struc(sdploc(lmiid):sdploc(lmiid+1)-1,i+1),K.s(lmiid),K.s(lmiid));
54                if nnz(Fi)>0
55                    [D,V] = getfactors(Fi);
56                    if length(D) <= options.sdplr.maxrank
57                        lrA(k).cons = i;
58                        lrA(k).start = sdploc(lmiid);
59                        lrA(k).D = D;
60                        lrA(k).V = V;
61                        k = k+1;
62                        removethese(i) = 1;
63                    end
64                end
65            end
66            removethese = find(removethese);
67            if ~isempty(removethese)
68                these = find((sdploc(lmiid+1)-1>= ix) & (ix>=sdploc(lmiid)) & ismember(jx,1+removethese));
69                sx(these) = 0;
70            end
71        end
72    else
73        % Just check those constraints declared low-rank by user
74        for lrdef = 1:length(lowrankdetails)
75            for lrconstraint = 1:length(lowrankdetails{lrdef}.id)
76                lmiid = lowrankdetails{lrdef}.id(lrconstraint);
77                removethese = zeros(1,size(F_struc,2)-1);
78                checkthese = lowrankdetails{lrdef}.variables;
79                if isempty(checkthese)
80                    checkthese = 1:size(F_struc,2)-1;
81                end
82                for i = checkthese
83                    Fi = reshape(F_struc(sdploc(lmiid):sdploc(lmiid+1)-1,i+1),K.s(lmiid),K.s(lmiid));
84                    if nnz(Fi)>0
85                        [D,V] = getfactors(Fi);
86                        if (options.sdplr.maxrank == 0) | (options.sdplr.maxrank ~= 0 & (length(D) <= options.sdplr.maxrank))
87                            lrA(k).cons = i;
88                            lrA(k).start = sdploc(lmiid);
89                            lrA(k).D = D;
90                            lrA(k).V = V;
91                            k = k+1;
92                            removethese(i) = 1;
93                        end
94                    end
95                end
96                removethese = find(removethese);
97                if ~isempty(removethese)
98                    these = find((sdploc(lmiid+1)-1>= ix) & (ix>=sdploc(lmiid)) & ismember(jx,1+removethese));
99                    sx(these) = 0;
100                    %F_struc(sdploc(lmiid):sdploc(lmiid+1)-1,1+removethese) = 0;
101                end
102            end
103        end
104        F_struc = sparse(ix,jx,sx,size(F_struc,1),size(F_struc,2));
105    end
106end
107
108% *********************************************
109% CALL SDPLR
110% *********************************************
111if options.showprogress;showprogress(['Calling ' interfacedata.solver.tag],options.showprogress);end
112solvertime = clock;
113if isempty(lrA)   
114   [x_s,y_s,info] = sdplr(F_struc(:,2:end),c,F_struc(:,1),K,pars);
115else
116    [x_s,y_s,info] = sdplr(F_struc(:,2:end),c,F_struc(:,1),K,pars,lrA);
117end
118solvertime = etime(clock,solvertime);
119
120% YALMIP format
121D_struc = x_s;
122x = -y_s;
123
124% No error codes currently...
125problem = 0;
126
127infostr = yalmiperror(problem,interfacedata.solver.tag);
128
129% Save ALL data sent to solver
130if options.savesolverinput
131    solverinput.A = F_struc(:,2:end);
132    solverinput.c = F_struc(:,1);
133    solverinput.b = c;
134    solverinput.K = K;
135    solverinput.pars = pars;
136else
137    solverinput = [];
138end
139
140% Save ALL data from the solution?
141if options.savesolveroutput
142    solveroutput.x = x_s;
143    solveroutput.y = y_s;
144    solveroutput.info = info;
145else
146    solveroutput = [];
147end
148
149% Standard interface
150output.Primal      = x(:);
151output.Dual        = D_struc;
152output.Slack       = [];
153output.problem     = problem;
154output.infostr     = infostr;
155output.solverinput = solverinput;
156output.solveroutput= solveroutput;
157output.solvertime  = solvertime;
158
159function [D,V] = getfactors(Fi)
160if nnz(Fi)>0
161    [v,d] = eig(full(Fi));
162    d = diag(d);
163    keep = find(abs(d)>1e-6);
164    V = v(:,keep);
165    D = d(keep);
166    % lrA(k).cons = i;
167    % lrA(k).start = sdploc(j);
168    % lrA(k).D = D;
169    % lrA(k).V = V;
170    % k = k+1;
171else
172    D = [];
173    V = [];
174end
175
176
Note: See TracBrowser for help on using the repository browser.