Cliques
=======

>>> import networkx as NX
>>> from networkx.generators.degree_seq import *
>>> from networkx.generators.random_graphs import *
>>> from networkx.algorithms.clique import *
>>> from networkx import convert_node_labels_to_integers as cnlti

>>> z=[3,4,3,4,2,4,2,1,1,1,1]
>>> G=cnlti(NX.generators.havel_hakimi_graph(z),first_label=1)
>>> H=NX.complete_graph(6)
>>> H=NX.relabel_nodes(H,dict( [(i,i+1) for i in range(6)]))
>>> H.remove_edges_from([(2,6),(2,5),(2,4),(1,3),(5,3)])

>>> cl=list(find_cliques(G))
>>> rcl=find_cliques_recursive(G)
>>> sorted(map(sorted,cl)) == sorted(map(sorted,rcl))
True
>>> cl
[[2, 6, 1, 3], [2, 6, 4], [5, 4, 7], [8, 9], [10, 11]]
>>> graph_clique_number(G)
4
>>> graph_clique_number(G,cliques=cl)
4

>>> hcl=list(find_cliques(H))
>>> sorted(map(sorted,hcl))
[[1, 2], [1, 4, 5, 6], [2, 3], [3, 4, 6]]

>>> graph_number_of_cliques(G)
5
>>> graph_number_of_cliques(G,cliques=cl)
5

>>> node_clique_number(G,1)
4
>>> node_clique_number(G,[1]).values()
[4]
>>> node_clique_number(G,[1,2]).values()
[4, 4]
>>> node_clique_number(G,[1,2])
{1: 4, 2: 4}
>>> node_clique_number(G,1)
4
>>> node_clique_number(G)
{1: 4, 2: 4, 3: 4, 4: 3, 5: 3, 6: 4, 7: 3, 8: 2, 9: 2, 10: 2, 11: 2}
>>> node_clique_number(G,cliques=cl)
{1: 4, 2: 4, 3: 4, 4: 3, 5: 3, 6: 4, 7: 3, 8: 2, 9: 2, 10: 2, 11: 2}

>>> number_of_cliques(G,1)
1
>>> number_of_cliques(G,[1]).values()
[1]
>>> number_of_cliques(G,[1,2]).values()
[1, 2]
>>> number_of_cliques(G,[1,2])
{1: 1, 2: 2}
>>> number_of_cliques(G,2)
2
>>> number_of_cliques(G)
{1: 1, 2: 2, 3: 1, 4: 2, 5: 1, 6: 2, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1}
>>> number_of_cliques(G,cliques=cl)
{1: 1, 2: 2, 3: 1, 4: 2, 5: 1, 6: 2, 7: 1, 8: 1, 9: 1, 10: 1, 11: 1}

>>> cliques_containing_node(G,1)
[[2, 6, 1, 3]]
>>> cliques_containing_node(G,[1]).values()
[[[2, 6, 1, 3]]]
>>> cliques_containing_node(G,[1,2]).values()
[[[2, 6, 1, 3]], [[2, 6, 1, 3], [2, 6, 4]]]
>>> cliques_containing_node(G,[1,2])
{1: [[2, 6, 1, 3]], 2: [[2, 6, 1, 3], [2, 6, 4]]}
>>> cliques_containing_node(G,1)
[[2, 6, 1, 3]]
>>> cliques_containing_node(G,2)
[[2, 6, 1, 3], [2, 6, 4]]
>>> cliques_containing_node(G,2,cliques=cl)
[[2, 6, 1, 3], [2, 6, 4]]
>>> len(cliques_containing_node(G))==11
True

>>> B=make_clique_bipartite(G)
>>> sorted(B.nodes())
[-5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
>>> H=project_down(B)
>>> H.adj == G.adj
True
>>> H1=project_up(B)
>>> H1.nodes()
[1, 2, 3, 4, 5]
>>> H2=make_max_clique_graph(G)
>>> H1.adj == H2.adj
True
