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

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

Added original make3d

File size: 2.2 KB
Line 
1function [Fdual,objdual,y,X] = primalize(F,obj)
2% PRIMALIZE Create the dual of an SDP given in dual form
3%
4% [Fd,objd,y] = primalize(F,obj)
5%
6% Input
7%  F   : Primal constraint in form C-Ay > 0, Fy = g
8%  obj : Primal cost maximize b'y
9%
10% Output
11%  Fd  : Dual constraints in form X>0, Trace(AiX)==bi+dt
12%  obj : Dual cost trace(CX)
13%  y   : The detected primal free variables
14%
15% Example
16%  See the HTML help.
17%
18% See also DUAL, SOLVESDP, SDPVAR, DUALIZE
19
20% Author Johan Löfberg
21% $Id: primalize.m,v 1.5 2005/12/19 15:27:31 joloef Exp $
22
23err = 0;
24
25% It's general, but not insanely general...
26if ~(islinear(F) & islinear(obj))
27    if nargout == 6
28        Fdual = set([]);objdual = [];y = []; err = 1;
29    else
30        error('Can only primalize linear problems');
31    end
32end
33if any(is(F,'socc'))
34    if nargout == 6
35        Fdual = set([]);objdual = [];y = []; err = 1;
36    else
37        error('Cannot primalize second order cone constraints');
38    end
39end
40if isa(obj,'sdpvar')
41    if any(is(F,'complex')) | is(obj,'complex')
42    if nargout == 6
43        Fdual = set([]);objdual = [];y = []; X = []; t = []; err = 1;
44    else
45        error('Cannot primalize complex-valued problems');
46    end
47    end
48end
49if any(is(F,'integer')) | any(is(F,'binary'))
50    if nargout == 6
51        Fdual = set([]);objdual = [];y = []; err = 1;
52    else
53        error('Cannot primalize discrete problems');
54    end
55end
56
57% Create model using the standard code
58model = export(F,obj,sdpsettings('solver','sedumi'));
59
60Fdual = set([]);
61xvec = [];
62if model.K.f > 0
63    t = sdpvar(model.K.f,1);
64    xvec = [xvec;t];
65end
66
67if model.K.l > 0
68    x = sdpvar(model.K.l,1);
69    xvec = [xvec;x];
70    Fdual = Fdual + set(x>0);
71end
72
73if model.K.q(1) > 0
74    for i = 1:length(model.K.q)
75        x = sdpvar(model.K.q(i),1);
76        xvec = [xvec;x];
77        Fdual = Fdual + set(cone(x(2:end),x(1)));
78    end
79end
80
81if model.K.s(1)>0
82    for i = 1:length(model.K.s)
83        X{i} = sdpvar(model.K.s(i),model.K.s(i));
84        xvec = [xvec;X{i}(:)];
85        Fdual = Fdual + set(X{i}>0);       
86    end
87end
88
89objdual = model.C(:)'*xvec;
90Fdual = Fdual + set(-model.b == model.A'*xvec);
91
92yvars = union(getvariables(F),getvariables(obj));
93y = recover(yvars);
94
95yalmip('associatedual',getlmiid(Fdual(end)),y);
96
97
98
99 
Note: See TracBrowser for help on using the repository browser.