123456789101112131415161718192021222324252627282930313233343536373839404142434445464748(**************************************************************************)(* *)(* Ocamlgraph: a generic graph library for OCaml *)(* Copyright (C) 2014-2015 *)(* Giselle Reis *)(* *)(* This software is free software; you can redistribute it and/or *)(* modify it under the terms of the GNU Library General Public *)(* License version 2.1, with the special exception on linking *)(* described in file LICENSE. *)(* *)(* This software 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. *)(* *)(**************************************************************************)moduletypeG=sigtypetmoduleV:Sig.COMPARABLEvalsucc:t->V.t->V.tlistvalfold_vertex:(V.t->'a->'a)->t->'a->'aendmoduleBron_Kerbosch(G:G)=structletrecbron_kerboschcliquelstgraphcliquecandidatesused=match(candidates,used)with|([],[])->clique::cliquelst|([],_)->cliquelst|(c,u)->let(_,_,cliques)=List.fold_left(fun(c,u,acc)v->(* Get the neighbors ignoring self-loops *)letn=List.filter(funnb->not(G.V.equalnbv))(G.succgraphv)inletc'=List.filter(funcv->List.exists(funv->G.V.equalvcv)n)cinletu'=List.filter(funcv->List.exists(funv->G.V.equalvcv)n)uinletc_minus_v=List.filter(funcv->not(G.V.equalcvv))cin(c_minus_v,(v::u),bron_kerboschaccgraph(v::clique)c'u'))(c,u,[])cincliques@cliquelstletmaximalcliquesg=letvertices=G.fold_vertex(funvacc->v::acc)g[]inbron_kerbosch[]g[]vertices[]end