%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Find all possible cliques in a graph. % A clique is a sub-graph that is % complete, i.e., any two vertices are connected. % % An undirected graph is represented by the set V of its % vertices and the set E of its edges. Each edge is % represented by the set of the two connected vertices. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clique(V,E,Clique) :- subset(Clique,V) & forall(I in Clique,forall(J in Clique,{I,J} in {{I} \ E})). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % A sample graph % graph(g1,{{a,b},{a,c},{b,c},{b,d},{c,d}}). % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % A sample goal % /* {log}=> graph(g1,G) & clique({a,b,c,d},G,Clique). G = {{a,b},{a,c},{b,c},{b,d},{c,d}}, Clique = {} Clique = {d} Clique = {c} Clique = {c,d} Clique = {b} Clique = {b,d} Clique = {b,c} Clique = {b,c,d} Clique = {a} Clique = {a,c} Clique = {a,b} Clique = {a,b,c} no */