1 | function [Fimage,objimage,x,y] = imagemodel(F,obj) |
---|
2 | % IMAGEMODEL Explicitely removes equality constraints from model. |
---|
3 | % |
---|
4 | % [Fi,hi,x,y] = imagemodel(F,h) |
---|
5 | % |
---|
6 | % Input |
---|
7 | % F : Constraint in form F(x)>0, Ax=b |
---|
8 | % h : objective function h(x) |
---|
9 | % |
---|
10 | % Output |
---|
11 | % Fi : Constraints in form F(y)>0 |
---|
12 | % hi : objective function h(y) |
---|
13 | % x : original variables |
---|
14 | % z : old variables expressed in basis y |
---|
15 | % |
---|
16 | % To obtain a solution in the original variables x, use assign(x,double(y)) |
---|
17 | % |
---|
18 | % Note that this reduction is automatically done when you call solvesdp and use |
---|
19 | % a solver that cannot handle equality constraints. Hence, there is typically no |
---|
20 | % reason to use this command, unless some further manipulations are going |
---|
21 | % to be done. |
---|
22 | % |
---|
23 | % See also DUALIZE, PRIMALIZE |
---|
24 | |
---|
25 | % Author Johan Löfberg |
---|
26 | % $Id: imagemodel.m,v 1.3 2005/04/29 08:05:01 joloef Exp $ |
---|
27 | |
---|
28 | % Check for unsupported problems |
---|
29 | err = 0; |
---|
30 | p1 = ~(isreal(F) & isreal(obj)); |
---|
31 | p2 = ~(islinear(F) & islinear(obj)); |
---|
32 | p3 = any(is(F,'integer')) | any(is(F,'binary')); |
---|
33 | if p1 | p2 | p3 |
---|
34 | if nargout == 5 |
---|
35 | Fdual = set([]);objdual = [];y = []; X = []; t = []; err = 1; |
---|
36 | else |
---|
37 | problems = {'Cannot imagalize complex-valued problems','Cannot imagalize nonlinear problems','Cannot imagalize discrete problems'}; |
---|
38 | error(problems{min(find([p1 p2 p3]))}); |
---|
39 | end |
---|
40 | end |
---|
41 | |
---|
42 | if any(is(F,'equality')) |
---|
43 | [model,recoverdata,solver,diagnostic,F] = compileinterfacedata(F,[],[],obj,sdpsettings('solver','sedumi','remove',1),0); |
---|
44 | if isfield(diagnostic,'problem') |
---|
45 | if diagnostic.problem == 1 |
---|
46 | warning('Problem is infeasible'); |
---|
47 | Fimage = []; |
---|
48 | objimage = []; |
---|
49 | x = []; |
---|
50 | y = []; |
---|
51 | return |
---|
52 | end |
---|
53 | end |
---|
54 | if isempty(model) |
---|
55 | Fimage = []; |
---|
56 | objimage = []; |
---|
57 | x = []; |
---|
58 | y = []; |
---|
59 | warning('Reduced problem does not have free variables. Optimal solution computed'); |
---|
60 | return |
---|
61 | end |
---|
62 | else |
---|
63 | Fimage = F; |
---|
64 | objimage = obj; |
---|
65 | x = recover(unique([depends(obj) depends(F)])); |
---|
66 | y = x; |
---|
67 | return |
---|
68 | end |
---|
69 | |
---|
70 | y = sdpvar(length(model.c),1); |
---|
71 | |
---|
72 | vecF = model.F_struc*[1;y]; |
---|
73 | K = model.K; |
---|
74 | Fimage = set([]); |
---|
75 | start = 1; |
---|
76 | if model.K.l > 0 |
---|
77 | Fimage = Fimage + set(vecF(start:start+K.l-1) > 0); |
---|
78 | start = start + K.l; |
---|
79 | end |
---|
80 | |
---|
81 | if model.K.q(1) > 0 |
---|
82 | for i = 1:length(model.K.q) |
---|
83 | z = vecF(start:start+K.q(i)-1) |
---|
84 | Fimage = Fimage + set(cone(z(2:end),z(1))); |
---|
85 | start = start + K.q(i); |
---|
86 | end |
---|
87 | end |
---|
88 | |
---|
89 | if model.K.s(1)>0 |
---|
90 | for i = 1:length(model.K.s) |
---|
91 | z = vecF(start:start+K.s(i)^2-1); |
---|
92 | Fimage = Fimage + set(reshape(z,K.s(i),K.s(i))); |
---|
93 | start = start + K.s(i)^2; |
---|
94 | end |
---|
95 | end |
---|
96 | |
---|
97 | objimage = model.c'*y+y'*model.Q*y+model.f; |
---|
98 | |
---|
99 | x = recover(recoverdata.used_variables); |
---|
100 | y = recoverdata.H*y+recoverdata.x_equ; |
---|