-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoverFct.m
42 lines (38 loc) · 1.16 KB
/
CoverFct.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
classdef CoverFct < SetFct
% Cover function F(A)= | U_{i in A} G_i|^alpha where
% W is a sparse matrix with W(i, j) = 1 if j in G_i, 0 otherwise
% alpha is any power <= 1
properties
W = sparse(1,1);
alpha = 1;
coverA = sparse(1,1);
end
methods
function F = CoverFct(W, alpha)
F.W = W;
F.alpha = alpha;
end
function [val, F] = obj(F, A)
if isequal(A, F.current_set)
val = F.current_val;
else
F.coverA = any(F.W(A,:), 1);
val = full(sum(F.coverA))^F.alpha;
F.current_set = A;
F.current_val = val;
end
end
function [new_val, F] = add(F, A, e)
[val, F] = F.obj(A);
if ismember(e, A)
new_val = val;
else
F.coverA = F.W(e,:)~=0 | F.coverA;
new_val = full(sum(F.coverA))^F.alpha;
F.current_set = union(A,e);
F.current_val = new_val;
end
end
% use rmv from base class, there's no more efficient implementation
end
end