1 | function dimacs = computedimacs(b,c,A,xin,y,s,K); |
---|
2 | % COMPUTEDIMACS |
---|
3 | % |
---|
4 | % min <C,X> s.t AX = b, X > 0 |
---|
5 | % max b'y s.t S-C+A'y =0, S > 0 |
---|
6 | |
---|
7 | % If no primal exist, fake till later |
---|
8 | if isempty(xin) |
---|
9 | x = c*0; |
---|
10 | else |
---|
11 | x = xin; |
---|
12 | end |
---|
13 | |
---|
14 | if isempty(s) |
---|
15 | s = c-A'*y; |
---|
16 | end |
---|
17 | |
---|
18 | xres = inf; |
---|
19 | sres = inf; |
---|
20 | |
---|
21 | % Not officially defined in DIMACS |
---|
22 | if K.f>0 |
---|
23 | sres = -min(norm(s(1:K.f),inf)); |
---|
24 | end |
---|
25 | |
---|
26 | % Errors in linear cone |
---|
27 | if K.l>0 |
---|
28 | xres = min(x(1+K.f:K.f+K.l)); |
---|
29 | sres = min(s(1+K.f:K.f+K.l)); |
---|
30 | end |
---|
31 | |
---|
32 | % Errors in quadratic cone |
---|
33 | if K.q(1)>0 |
---|
34 | top = K.f+K.l; |
---|
35 | for i = 1:length(K.q) |
---|
36 | X = x(1+top:top+K.q(i)); |
---|
37 | S = s(1+top:top+K.q(i)); |
---|
38 | xres = min(xres,X(1)-norm(X(2:end))); |
---|
39 | sres = min(sres,S(1)-norm(S(2:end))); |
---|
40 | top = top + K.q(i); |
---|
41 | end |
---|
42 | end |
---|
43 | |
---|
44 | % Errors in semidefinite cone |
---|
45 | if K.s(1)>0 |
---|
46 | top = K.f+K.l+K.q+K.r; |
---|
47 | for i = 1:length(K.s) |
---|
48 | X = reshape(x(1+top:top+K.s(i)^2),K.s(i),K.s(i)); |
---|
49 | S = reshape(s(1+top:top+K.s(i)^2),K.s(i),K.s(i)); |
---|
50 | xres = min(xres,min(eig(full(X)))); |
---|
51 | sres = min(sres,min(eig(full(S)))); |
---|
52 | top = top + K.s(i)^2; |
---|
53 | end |
---|
54 | end |
---|
55 | |
---|
56 | err1 = norm(b-A*x)/(1 + norm(b,inf)); |
---|
57 | err2 = max(0,-xres)/(1 + norm(b,inf)); |
---|
58 | err3 = conenorm(s-(c-A'*y),K)/(1+norm(c,inf)); |
---|
59 | %err3 = norm(s-(c-A'*y))/(1+norm(c,inf)); % Used by some solvers |
---|
60 | err4 = max(0,-sres)/(1+max(abs(c))); |
---|
61 | err5 = (c'*x-b'*y)/(1+abs(c'*x)+abs(b'*y)); |
---|
62 | err6 = x'*(c-A'*y)/(1+abs(c'*x)+abs(b'*y)); |
---|
63 | |
---|
64 | % No primal was computed |
---|
65 | if isempty(xin) |
---|
66 | err1 = nan; |
---|
67 | err2 = nan; |
---|
68 | err5 = nan; |
---|
69 | err6 = nan; |
---|
70 | end |
---|
71 | dimacs = [err1 err2 err3 err4 err5 err6]; |
---|
72 | |
---|
73 | function t = conenorm(s,K) |
---|
74 | |
---|
75 | % Implementation of the norm described on |
---|
76 | % http://plato.asu.edu/dimacs/node3.html |
---|
77 | |
---|
78 | t = 0; |
---|
79 | |
---|
80 | if K.f + K.l>0 |
---|
81 | t = t + norm(s(1:K.f+K.l)); |
---|
82 | end |
---|
83 | |
---|
84 | top = 1+K.f+K.l; |
---|
85 | if K.q(1)>0 |
---|
86 | for i = 1:length(K.q) |
---|
87 | t = t + norm(s(top:top+K.q(i)-1)); |
---|
88 | top = top + K.q(i); |
---|
89 | end |
---|
90 | end |
---|
91 | |
---|
92 | if K.s(1)>0 |
---|
93 | for i = 1:length(K.s) |
---|
94 | S = reshape(s(top:top+K.s(i)^2-1),K.s(i),K.s(i)); |
---|
95 | t = t + norm(S,'fro'); |
---|
96 | top = top + K.s(i)^2; |
---|
97 | end |
---|
98 | end |
---|