1 | function output = calllmilab(interfacedata) |
---|
2 | |
---|
3 | % Author Johan Löfberg |
---|
4 | % $Id: calllmilab.m,v 1.4 2005/05/07 13:53:20 joloef Exp $ |
---|
5 | |
---|
6 | % Retrieve needed data |
---|
7 | options = interfacedata.options; |
---|
8 | F_struc = interfacedata.F_struc; |
---|
9 | c = interfacedata.c; |
---|
10 | K = interfacedata.K; |
---|
11 | x0 = interfacedata.x0; |
---|
12 | ub = interfacedata.ub; |
---|
13 | lb = interfacedata.lb; |
---|
14 | |
---|
15 | % Bounded variables converted to constraints |
---|
16 | if ~isempty(ub) |
---|
17 | [F_struc,K] = addbounds(F_struc,K,ub,lb); |
---|
18 | end |
---|
19 | |
---|
20 | % Define lmilab variables (is this the way to do it?) |
---|
21 | setlmis([]) |
---|
22 | for i = 1:length(c) |
---|
23 | [X,ndec,Xdec] = lmivar(2,[1 1]); |
---|
24 | end |
---|
25 | |
---|
26 | % Can't linear constraints be defined more easily? |
---|
27 | lmicount = 1; |
---|
28 | top = 1; |
---|
29 | if K.l>0 |
---|
30 | for i = 1:K.l |
---|
31 | lmiterm([-lmicount 1 1 0],F_struc(i,1)); |
---|
32 | for j = 1:length(c) |
---|
33 | lmiterm([-lmicount 1 1 j],F_struc(i,j+1),1); |
---|
34 | end |
---|
35 | lmicount = lmicount+1; |
---|
36 | end |
---|
37 | top = top + K.l; |
---|
38 | end |
---|
39 | |
---|
40 | % The LMIs |
---|
41 | if K.s(1)>0 |
---|
42 | for i = 1:length(K.s) |
---|
43 | n = K.s(i); |
---|
44 | lmiterm([-lmicount 1 1 0],full(reshape(F_struc(top:top+n^2-1,1),n,n))); |
---|
45 | for j = 1:length(c) |
---|
46 | lmiterm([-lmicount 1 1 j],full(reshape(F_struc(top:top+n^2-1,j+1),n,n)),1); |
---|
47 | end |
---|
48 | top = top+n^2; |
---|
49 | lmicount = lmicount+1; |
---|
50 | end |
---|
51 | end |
---|
52 | lmisys=getlmis; |
---|
53 | |
---|
54 | % Convert options |
---|
55 | ops = struct2cell(options.lmilab);ops = [ops{1:end}]; |
---|
56 | if options.verbose>0 |
---|
57 | ops = [ops 0]; |
---|
58 | else |
---|
59 | ops = [ops 1]; |
---|
60 | end |
---|
61 | |
---|
62 | if options.savedebug |
---|
63 | save lmilabdebug lmisys c ops |
---|
64 | end |
---|
65 | |
---|
66 | % Solve... |
---|
67 | if options.showprogress;showprogress(['Calling ' interfacedata.solver.tag],options.showprogress);end |
---|
68 | solvertime = clock; |
---|
69 | if nnz(c)==0 |
---|
70 | [copt,x]=feasp(lmisys,ops); |
---|
71 | else |
---|
72 | [copt,x]=mincx(lmisys,full(c),ops); |
---|
73 | end |
---|
74 | solvertime = etime(clock,solvertime); |
---|
75 | |
---|
76 | % No status |
---|
77 | if isempty(x) |
---|
78 | problem = 1; |
---|
79 | x = repmat(nan,length(c),1); |
---|
80 | else |
---|
81 | problem = 0; |
---|
82 | end |
---|
83 | infostr = yalmiperror(problem,interfacedata.solver.tag); |
---|
84 | |
---|
85 | % No duals... |
---|
86 | D_struc = []; |
---|
87 | |
---|
88 | if options.savesolveroutput |
---|
89 | solveroutput.copt = copt; |
---|
90 | solveroutput.x = x; |
---|
91 | else |
---|
92 | solveroutput = []; |
---|
93 | end |
---|
94 | |
---|
95 | if options.savesolverinput |
---|
96 | solverinput.lmisys = lmisys; |
---|
97 | solverinput.c = c; |
---|
98 | solverinput.ops = ops; |
---|
99 | else |
---|
100 | solverinput = []; |
---|
101 | end |
---|
102 | |
---|
103 | % Standard interface |
---|
104 | output.Primal = x; |
---|
105 | output.Dual = D_struc; |
---|
106 | output.Slack = []; |
---|
107 | output.problem = problem; |
---|
108 | output.infostr = infostr; |
---|
109 | output.solverinput = solverinput; |
---|
110 | output.solveroutput= solveroutput; |
---|
111 | output.solvertime = solvertime; |
---|