[37] | 1 | function [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 | |
---|
| 23 | err = 0; |
---|
| 24 | |
---|
| 25 | % It's general, but not insanely general... |
---|
| 26 | if ~(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 |
---|
| 32 | end |
---|
| 33 | if 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 |
---|
| 39 | end |
---|
| 40 | if 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 |
---|
| 48 | end |
---|
| 49 | if 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 |
---|
| 55 | end |
---|
| 56 | |
---|
| 57 | % Create model using the standard code |
---|
| 58 | model = export(F,obj,sdpsettings('solver','sedumi')); |
---|
| 59 | |
---|
| 60 | Fdual = set([]); |
---|
| 61 | xvec = []; |
---|
| 62 | if model.K.f > 0 |
---|
| 63 | t = sdpvar(model.K.f,1); |
---|
| 64 | xvec = [xvec;t]; |
---|
| 65 | end |
---|
| 66 | |
---|
| 67 | if model.K.l > 0 |
---|
| 68 | x = sdpvar(model.K.l,1); |
---|
| 69 | xvec = [xvec;x]; |
---|
| 70 | Fdual = Fdual + set(x>0); |
---|
| 71 | end |
---|
| 72 | |
---|
| 73 | if 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 |
---|
| 79 | end |
---|
| 80 | |
---|
| 81 | if 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 |
---|
| 87 | end |
---|
| 88 | |
---|
| 89 | objdual = model.C(:)'*xvec; |
---|
| 90 | Fdual = Fdual + set(-model.b == model.A'*xvec); |
---|
| 91 | |
---|
| 92 | yvars = union(getvariables(F),getvariables(obj)); |
---|
| 93 | y = recover(yvars); |
---|
| 94 | |
---|
| 95 | yalmip('associatedual',getlmiid(Fdual(end)),y); |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | |
---|