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

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

Added original make3d

File size: 2.5 KB
Line 
1function [C,A,b,blk] = dsdpdata(F,h)
2%DSDPDATA Internal function create DSDP data
3
4% Author Johan Löfberg
5% $Id: dsdpdata.m,v 1.3 2004/11/24 09:13:05 johanl Exp $
6
7if ~(isempty(F) | isa(F,'lmi'))
8        help lmi
9        error('First argument (F) should be an lmi object. See help text above');
10end
11
12if ~(isempty(h) | isa(h,'sdpvar'))
13        help solvesdp
14        error('Third argument (the objective function h) should be an sdpvar object (or empty). See help text above');
15end
16
17[ProblemString,real_data] = catsdp(F);
18if (real_data == 0)
19        error('DSDP does not support complex data')
20end
21
22% This one is used a lot
23nvars = sdpvar('nvars');
24
25% Convert the objective
26onlyfeasible = 0;
27if isempty(h)
28        c=zeros(nvars,1);
29else 
30        [n,m]=size(h);
31        if ~((n==1) & (m==1))
32                error('Scalar expression to minimize please.');
33        else
34                lmi_variables = getvariables(h);
35                c  = zeros(nvars,1);
36                for i=1:length(lmi_variables)
37                        c(lmi_variables(i))=getbasematrix(h,lmi_variables(i));
38                end;
39        end
40end
41
42[F_struc,K,F_blksz]  = lmi2spstruct(F);
43
44% Which sdpvar variables are actually in the problem
45used_variables_LMI = find(any(F_struc(:,2:end),1));
46used_variables_obj = find(any(c',1));
47used_variables = uniquestripped([used_variables_LMI used_variables_obj]);
48
49% Check for unbounded variables
50unbounded_variables = setdiff(used_variables_obj,used_variables_LMI);
51if ~isempty(unbounded_variables)
52        % Remove unbounded variable from problem
53        used_variables = setdiff(used_variables,unbounded_variables);
54end
55
56% Pick out the necessary rows
57if length(used_variables)<nvars
58        c = c(used_variables);
59        F_struc = sparse(F_struc(:,[1 1+[used_variables]]));
60end
61
62
63if (K.f>0)
64        % Extract the inequalities
65        A_equ = F_struc(1:K.f,2:end);
66        b_equ = -F_struc(1:K.f,1);
67       
68        % Find feasible (turn off annoying warning on PC)
69        % Using method from Nocedal-Wright book
70        showprogress('Solving equalities',options.ShowProgress);
71        [Q,R] = qr(A_equ');
72        n = size(R,2);
73        Q1 = Q(:,1:n);
74        R = R(1:n,:);
75        x_equ = Q1*(R'\b_equ); 
76        % Exit if no consistent solution exist
77        if (norm(A_equ*x_equ-b_equ)>sqrt(eps))
78                error('Linear constraints inconsistent.');
79                return
80        end
81        % We dont need the rows for equalities anymore
82        F_struc = F_struc(K.f+1:end,:);
83        K.f = 0;
84       
85        % We found a new basis
86        H = Q(:,n+1:end); % New basis
87       
88        % objective in new basis
89        c = H'*c;
90        % LMI in new basis
91        F_struc = [F_struc*[1;x_equ] F_struc(:,2:end)*H];       
92else
93        % For simpliciy we introduce a dummy coordinate change
94        x_equ = 0;
95        H     = 1;
96end
97
98% Convert from SP format (same format as SDPT3-2.3)
99[C,A,b,blk] = sp2sdpt323(F_struc,F_blksz,c);
Note: See TracBrowser for help on using the repository browser.