-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cliques.ml
33 lines (33 loc) · 1.04 KB
/
Cliques.ml
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
let max_cliques g =
(* returns the accumulator CLIQUES plus all maximal cliques C that
are supersets of CLIQUE, disjoint from NOTS, and subset of CANDS
union CLIQUE. *)
let rec extend clique cands nots cliques =
if IntSet.is_empty cands
then
if IntSet.is_empty nots
then clique :: cliques
else cliques
else
let pivot = IntSet.choose cands in
let _, _, cliques =
IntSet.fold
(fun ((cands, nots, cliques) as state) u ->
if Graph.is_connected g u pivot
then state
else
let cands = IntSet.remove cands u in
let clique' = IntSet.add clique u in
let u_neighbors = Graph.neighbors g u in
let cands' = IntSet.intersection cands u_neighbors in
let nots' = IntSet.intersection nots u_neighbors in
let cliques = extend clique' cands' nots' cliques in
let nots = IntSet.add nots u in
(cands, nots, cliques))
cands
(cands, nots, cliques)
in
cliques
in
extend IntSet.empty (Graph.vertices g) IntSet.empty []
;;