-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrestrict_max_cliques_to_size.m
57 lines (51 loc) · 1.94 KB
/
restrict_max_cliques_to_size.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
function [ restrictedCliques ] = restrict_max_cliques_to_size( ...
maximalCliques, maxSize, firstVertex, secondVertex )
% ----------------------------------------------------------------
% RESTRICT CLIQUES TO SIZE
% written by Chad Giusti, 6/2014
%
% Given a cell array whose elements are positive integer arrays
% listing vertices in the maximal cliques in a graph, return a
% cell array of cliques appearing in the graph of size no larger
% than maxSize. The list may contain repetitions.
%
% INPUTS:
% maximalCliques: cell array of positive integer arrays listing
% vertices in maximal cliques of a graph
% maxSize: maximum clique size of interest
%
% OUTPUTS:
% restrictedCliques: maximal cliques in the graph of size no
% more than maxSize
%
% ----------------------------------------------------------------
numSmallCliques = 0;
for j=1:length(maximalCliques)
if (length(maximalCliques{j}) < maxSize)
numSmallCliques = numSmallCliques + 1;
else
numSmallCliques = numSmallCliques + ...
nchoosek(length(maximalCliques{j})-2, maxSize-2);
end
end
restrictedCliques = cell(numSmallCliques,1);
thisSmallClique = 1;
for j=1:length(maximalCliques)
if length(maximalCliques{j}) < maxSize
restrictedCliques{thisSmallClique} = maximalCliques{j};
thisSmallClique = thisSmallClique + 1;
else
vertices = maximalCliques{j};
subVertices = vertices((vertices ~= firstVertex) & ...
(vertices ~= secondVertex)); % all new cliques will contain
% the edge removed at this
% filtration level
theseSmallCliques = nchoosek(subVertices, maxSize-2);
for k=1:size(theseSmallCliques,1)
restrictedCliques{thisSmallClique} = ...
[theseSmallCliques(k,:) firstVertex secondVertex];
thisSmallClique = thisSmallClique + 1;
end
end
end
end