1 | function [F,h] = loadsdpafile(varargin) |
---|
2 | %LOADSDPAFILE Loads a problem definition in the SDPA format |
---|
3 | % |
---|
4 | % [F,h] = loadsdpafile('filename') Loads the problem min(h(x)), F(x)>0 from file 'filename' |
---|
5 | % [F,h] = loadsdpafile A "Open" - box will be opened |
---|
6 | |
---|
7 | % Author Johan Löfberg |
---|
8 | % $Id: loadsdpafile.m,v 1.3 2005/06/17 13:02:01 joloef Exp $ |
---|
9 | |
---|
10 | filename = varargin{1}; |
---|
11 | |
---|
12 | % Does the file exist |
---|
13 | if ~exist(filename) |
---|
14 | filename = [filename '.dat-s']; |
---|
15 | if ~exist(filename) |
---|
16 | error(['No such file.']); |
---|
17 | end |
---|
18 | end |
---|
19 | |
---|
20 | % Load using SeDuMi |
---|
21 | try |
---|
22 | [At,b,c,K,perm] = fromsdpa(filename); |
---|
23 | catch |
---|
24 | error('LOADSDPAFILE currently requires SeDuMi to be installed'); |
---|
25 | end |
---|
26 | |
---|
27 | nvars = length(b); |
---|
28 | x = sdpvar(nvars,1); |
---|
29 | |
---|
30 | F = set([]); |
---|
31 | top = 1; |
---|
32 | if isfield(K,'l') |
---|
33 | if K.l(1)>0 |
---|
34 | X = c(top:top+K.l-1)-At(top:top+K.l-1,:)*x; |
---|
35 | F = F + set(X(:)); |
---|
36 | top = top + K.l; |
---|
37 | end |
---|
38 | end |
---|
39 | |
---|
40 | if isfield(K,'s') |
---|
41 | if K.s(1)>0 |
---|
42 | for i = 1:length(K.s) |
---|
43 | [ix,iy,iv] = find([c(top:top+K.s(i)^2-1) At(top:top+K.s(i)^2-1,:)]); |
---|
44 | off = (ix-1)/(K.s(i)+1); |
---|
45 | if all(off == round(off)) |
---|
46 | X = c(top:top+K.s(i)^2-1)-At(top:top+K.s(i)^2-1,:)*x; |
---|
47 | F = F + set(diag(reshape(X,K.s(i),K.s(i))) > 0); |
---|
48 | top = top + K.s(i)^2; |
---|
49 | else |
---|
50 | X = c(top:top+K.s(i)^2-1)-At(top:top+K.s(i)^2-1,:)*x; |
---|
51 | F = F + set(reshape(X,K.s(i),K.s(i)) > 0); |
---|
52 | top = top + K.s(i)^2; |
---|
53 | end |
---|
54 | end |
---|
55 | end |
---|
56 | end |
---|
57 | |
---|
58 | h = -b'*x; |
---|
59 | |
---|