-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluateCoLO.m
More file actions
114 lines (106 loc) · 4.13 KB
/
evaluateCoLO.m
File metadata and controls
114 lines (106 loc) · 4.13 KB
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
111
112
113
function [primalObjValue, dualObjValue, primalfeasibility, dualfeasibility] = ...
evaluateCoLO(x,y,A,b,c,K,J,cliqueDomain,cliqueRange);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This file is a component of SparseCoLO
% Copyright (C) 2009
% Masakazu Kojima Group
% Department of Mathematical and Computing Sciences
% Tokyo Institute of Technology
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
if size(c,1) < size(c,2)
c = c';
end
if size(b,1) < size(b,2)
b = b';
end
primalObjValue = full(c'*x);
dualObjValue = full(b'*y);
primalfeasibility = 0.0;
primalResidual = (A*x - b)';
% isDomain = 0;
primalfeasibility = primalfeasibility + ...
computeOneCone(primalResidual,J,0,cliqueRange);
% isDomain = 1;
primalfeasibility = primalfeasibility + ...
computeOneCone(x,K,1,cliqueDomain);
dualfeasibility = 0.0;
dualResidual = (c-A'*y)';
% dualfeasibility = dualfeasibility + ...
% computeOneCone(dualResidual,K,1,cliqueDomain);
% dualfeasibility = dualfeasibility + ...
% computeOneCone(y,J,0,cliqueRange);
% isDomain = 0;
dualfeasibility = dualfeasibility + ...
computeOneCone(dualResidual,K,0,cliqueDomain);
% isDomain = 1;
dualfeasibility = dualfeasibility + ...
computeOneCone(y,J,1,cliqueRange);
debugSW = 1;
if debugSW == 1
fprintf('primalObjValue = %+15.8e, dualObjValue = %+15.8e, gap = %+7.2e\n',...
primalObjValue,dualObjValue,primalObjValue-dualObjValue);
fprintf('primalfeasibility = %+7.2e\n',primalfeasibility);
fprintf('dualfeasibility = %+7.2e\n',dualfeasibility);
end
return
end
function feasibility = computeOneCone(residual,K,isDomain,clique)
rowPointer = 0;
feasibility = 0;
if isfield(K,'f') && ~isempty(K.f) && K.f > 0
% if isDomain == 1
% feasibility = feasibility + ...
% norm(residual(rowPointer+1:rowPointer+K.f),inf);
% end
if isDomain == 0
feasibility = feasibility + ...
norm(residual(rowPointer+1:rowPointer+K.f),inf);
end
rowPointer = rowPointer + K.f;
end % end of K.f
if isfield(K,'l') && ~isempty(K.l) && K.l > 0
feasibility = feasibility + max([0, - min(residual(rowPointer+1:rowPointer+K.l))]);
rowPointer = rowPointer + K.l;
end % end of K.l
if isfield(K,'q') && ~isempty(K.q)
for i=1:length(K.q)
feasibility = feasibility + max([0, -(residual(rowPointer+1) + norm(residual(rowPointer+2:rowPointer+K.q(i))))]);
rowPointer = rowPointer + K.q(i);
end
end % end of K.q
if isfield(K,'s') && ~isempty(K.s)
for i=1:length(K.s)
oneMat = reshape(residual(rowPointer+1:rowPointer+K.s(i)*K.s(i)),K.s(i),K.s(i));
oneMat = (oneMat + oneMat')/2;
if isempty(clique) || clique{i}.NoC == 1
% clique{i}
d = eig(oneMat);
feasibility = feasibility + max([0, -min(d)]);
else
for j=1:clique{i}.NoC
idx = clique{i}.Set{j};
d = eig(oneMat(idx,idx));
feasibility = feasibility + max([0, -min(d)]);
end
end
rowPointer = rowPointer + K.s(i)*K.s(i);
end
end % end of K.s
end