forked from yalmip/YALMIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callpensdp.m
113 lines (99 loc) · 2.5 KB
/
callpensdp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function output = callpensdpm(interfacedata);
% Retrieve needed data
options = interfacedata.options;
F_struc = interfacedata.F_struc;
c = interfacedata.c;
K = interfacedata.K;
x0 = interfacedata.x0;
ub = interfacedata.ub;
lb = interfacedata.lb;
% Bounded variables converted to constraints
if ~isempty(ub)
[F_struc,K] = addStructureBounds(F_struc,K,ub,lb);
end
% *******************************
% CONVERT FROM INTERNAL FORMAT
% *******************************
penstruct = sedumi2pen(F_struc,K,c,x0);
% **************************
% COPY OPTIONS
% **************************
ops = struct2cell(options.pensdp);ops = [ops{1:end}];
penstruct.ioptions = ops(1:8);
penstruct.foptions = ops(9:end);
penstruct.ioptions(4) = max(0,min(3,options.verbose+1));
if penstruct.ioptions(4)==1
penstruct.ioptions(4)=0;
end
% FIX
if penstruct.mconstr == 0
penstruct.msizes = [];
end
if options.savedebug
save pensdpdebug penstruct
end
%**************************
% CALL PENSDP
%**************************
showprogress('Calling PENSDP',options.showprogress);
solvertime = tic;
[x, fx, u, iresults, fresults, iflag] = pen(penstruct);
solvertime = toc(solvertime);
% Get dual variable (this must be possible to do easier...)
u = u(:);
D_struc = u(1:1:K.l);
if length(K.s)>0
if K.s(1)>0
pos = K.l+1;
for i = 1:length(K.s)
temp = zeros(K.s(i),K.s(i));
vecZ = u(pos:pos+0.5*K.s(i)*(K.s(i)+1)-1);
top = 1;
for j = 1:K.s(i)
len = K.s(i)-j+1;
temp(j:end,j)=vecZ(top:top+len-1);top=top+len;
end
temp = (temp+temp');j = find(speye(K.s(i)));temp(j)=temp(j)/2;
D_struc = [D_struc;temp(:)];
pos = pos + (K.s(i)+1)*K.s(i)/2;
end
end
end
switch iflag
case 0
problem = 0;
case 1
problem = 4;
case 2
problem = 1;
case 3
problem = 4;
case 4
problem = 3;
case 5
problem = 7;
case 6
problem = 11;
case 7
problem = 9;
otherwise
problem = -1;
end
infostr = yalmiperror(problem,'PENSDP/TOMLAB');
if options.savesolveroutput
solveroutput.f = f;
solveroutput.x = x;
solveroutput.u = u;
solveroutput.iflag = iflag;
solveroutput.niter = niter;
solveroutput.feas = feas;
else
solveroutput = [];
end
if options.savesolverinput
solverinput.penstruct = penstruct;
else
solverinput = [];
end
% Standard interface
output = createOutputStructure(x(:),D_struc,[],problem,infostr,solverinput,solveroutput,solvertime);