[37] | 1 | function [F,h] = loadsedumidata(varargin) |
---|
| 2 | %LOADSEDUMIDATA Loads a problem definition in the SeDuMi format |
---|
| 3 | % |
---|
| 4 | % [F,h] = loadsedumidata('filename') Loads the problem min(h(x)), F(x)>0 from file 'filename' |
---|
| 5 | % [F,h] = loadsedumidata An "Open" - box will be opened |
---|
| 6 | |
---|
| 7 | % Author Johan Löfberg |
---|
| 8 | % $Id: loadsedumidata.m,v 1.2 2005/09/16 08:10:24 joloef Exp $ |
---|
| 9 | |
---|
| 10 | filename = varargin{1}; |
---|
| 11 | |
---|
| 12 | % Does the file exist |
---|
| 13 | if ~exist(filename) |
---|
| 14 | filename = [filename '.mat']; |
---|
| 15 | if ~exist(filename) |
---|
| 16 | error(['No such file.']); |
---|
| 17 | end |
---|
| 18 | end |
---|
| 19 | |
---|
| 20 | load(filename) |
---|
| 21 | try |
---|
| 22 | b = b(:); |
---|
| 23 | c = c(:); |
---|
| 24 | if ~exist('At') |
---|
| 25 | At = A; |
---|
| 26 | end |
---|
| 27 | K = K; |
---|
| 28 | catch |
---|
| 29 | error('The file should contain the data At, b, c and K'); |
---|
| 30 | end |
---|
| 31 | |
---|
| 32 | nvars = length(b); |
---|
| 33 | x = sdpvar(nvars,1); |
---|
| 34 | |
---|
| 35 | if size(At,2)~=length(b) |
---|
| 36 | At = At'; |
---|
| 37 | end |
---|
| 38 | |
---|
| 39 | F = set([]); |
---|
| 40 | top = 1; |
---|
| 41 | |
---|
| 42 | if isvalidfield(K,'f') |
---|
| 43 | X = c(top:top+K.f-1)-At(top:top+K.f-1,:)*x; |
---|
| 44 | F = F + set(X(:) == 0); |
---|
| 45 | top = top + K.f; |
---|
| 46 | end |
---|
| 47 | |
---|
| 48 | if isvalidfield(K,'l') |
---|
| 49 | X = c(top:top+K.l-1)-At(top:top+K.l-1,:)*x; |
---|
| 50 | F = F + set(X(:)); |
---|
| 51 | top = top + K.l; |
---|
| 52 | end |
---|
| 53 | |
---|
| 54 | if isvalidfield(K,'q') |
---|
| 55 | for i = 1:length(K.q) |
---|
| 56 | X = c(top:top+K.q(i)-1)-At(top:top+K.q(i)-1,:)*x; |
---|
| 57 | F = F + set(cone(X(2:end),X(1))); |
---|
| 58 | top = top + K.q(i); |
---|
| 59 | end |
---|
| 60 | end |
---|
| 61 | |
---|
| 62 | if isvalidfield(K,'r') |
---|
| 63 | for i = 1:length(K.r) |
---|
| 64 | X = c(top:top+K.r(i)-1)-At(top:top+K.r(i)-1,:)*x; |
---|
| 65 | F = F + set(rcone(X(3:end),X(2),X(1))); |
---|
| 66 | top = top + K.r(i); |
---|
| 67 | end |
---|
| 68 | end |
---|
| 69 | |
---|
| 70 | if isvalidfield(K,'s') |
---|
| 71 | for i = 1:length(K.s) |
---|
| 72 | [ix,iy,iv] = find([c(top:top+K.s(i)^2-1) At(top:top+K.s(i)^2-1,:)]); |
---|
| 73 | off = (ix-1)/(K.s(i)+1); |
---|
| 74 | if all(off == round(off)) |
---|
| 75 | X = c(top:top+K.s(i)^2-1)-At(top:top+K.s(i)^2-1,:)*x; |
---|
| 76 | F = F + set(diag(reshape(X,K.s(i),K.s(i))) > 0); |
---|
| 77 | top = top + K.s(i)^2; |
---|
| 78 | else |
---|
| 79 | X = c(top:top+K.s(i)^2-1)-At(top:top+K.s(i)^2-1,:)*x; |
---|
| 80 | F = F + set(reshape(X,K.s(i),K.s(i)) > 0); |
---|
| 81 | top = top + K.s(i)^2; |
---|
| 82 | end |
---|
| 83 | end |
---|
| 84 | end |
---|
| 85 | |
---|
| 86 | h = -b'*x; |
---|
| 87 | |
---|
| 88 | function ok = isvalidfield(K,fld) |
---|
| 89 | ok = 0; |
---|
| 90 | if isfield(K,fld) |
---|
| 91 | s = getfield(K,fld); |
---|
| 92 | if prod(size(s))>0 |
---|
| 93 | if s(1)>0 |
---|
| 94 | ok = 1; |
---|
| 95 | end |
---|
| 96 | end |
---|
| 97 | end |
---|
| 98 | |
---|