source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/extras/computedimacs.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.0 KB
Line 
1function 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
8if isempty(xin)
9    x = c*0;
10else
11    x = xin;
12end
13
14if isempty(s)
15    s = c-A'*y;
16end
17
18xres = inf;
19sres = inf;
20
21% Not officially defined in DIMACS
22if K.f>0
23    sres = -min(norm(s(1:K.f),inf));
24end
25
26% Errors in linear cone
27if 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));
30end
31
32% Errors in quadratic cone
33if 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
42end
43
44% Errors in semidefinite cone
45if 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
54end
55
56err1 = norm(b-A*x)/(1 + norm(b,inf));
57err2 = max(0,-xres)/(1 + norm(b,inf));
58err3 = 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
60err4 = max(0,-sres)/(1+max(abs(c)));
61err5 = (c'*x-b'*y)/(1+abs(c'*x)+abs(b'*y));
62err6 = x'*(c-A'*y)/(1+abs(c'*x)+abs(b'*y));
63
64% No primal was computed
65if isempty(xin)
66    err1 = nan;
67    err2 = nan;
68    err5 = nan;
69    err6 = nan;
70end
71dimacs = [err1 err2 err3 err4 err5 err6];
72
73function t = conenorm(s,K)
74
75% Implementation of the norm described on
76% http://plato.asu.edu/dimacs/node3.html
77
78t = 0;
79
80if K.f + K.l>0
81    t = t + norm(s(1:K.f+K.l));
82end
83
84top = 1+K.f+K.l;
85if 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
90end
91
92if 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
98end
Note: See TracBrowser for help on using the repository browser.