ó žÃÒYc@sSddlmZddlZdjddgƒZdgZdd„Zd„Z dS( iÿÿÿÿ(t defaultdictNs s Conrad Lee s%Aric Hagberg tk_clique_communitiesc csR|dkr"tjd|ƒ‚n|dkr@tj|ƒ}ng|D]$}t|ƒ|krGt|ƒ^qG}ttƒ}x0|D](}x|D]}||j|ƒq‘Wq„Wtj ƒ}|j |ƒxZ|D]R}xIt ||ƒD]8}t|j |ƒƒ|dkræ|j ||ƒqæqæWqÐWx%tj|ƒD]} tj| ŒVq6WdS(sdFind k-clique communities in graph using the percolation method. A k-clique community is the union of all cliques of size k that can be reached through adjacent (sharing k-1 nodes) k-cliques. Parameters ---------- G : NetworkX graph k : int Size of smallest clique cliques: list or generator Precomputed cliques (use networkx.find_cliques(G)) Returns ------- Yields sets of nodes, one for each k-clique community. Examples -------- >>> from networkx.algorithms.community import k_clique_communities >>> G = nx.complete_graph(5) >>> K5 = nx.convert_node_labels_to_integers(G,first_label=2) >>> G.add_edges_from(K5.edges()) >>> c = list(k_clique_communities(G, 4)) >>> list(c[0]) [0, 1, 2, 3, 4, 5, 6] >>> list(k_clique_communities(G, 6)) [] References ---------- .. [1] Gergely Palla, Imre Derényi, Illés Farkas1, and Tamás Vicsek, Uncovering the overlapping community structure of complex networks in nature and society Nature 435, 814-818, 2005, doi:10.1038/nature03607 isk=%d, k must be greater than 1.iN(tnxt NetworkXErrortNonet find_cliquestlent frozensetRtlisttappendtGraphtadd_nodes_fromt_get_adjacent_cliquest intersectiontadd_edgetconnected_componentstunion( tGtktcliquestctmembership_dicttcliquetnodet perc_grapht adj_cliquet component((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/community/kclique.pyR s"'  1      cCsOtƒ}x?|D]7}x.||D]"}||kr!|j|ƒq!q!WqW|S(N(tsettadd(RRtadjacent_cliquestnR((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/community/kclique.pyR Ms    ( t collectionsRtnetworkxRtjoint __author__t__all__RRR (((s{/private/var/folders/w6/vb91730s7bb1k90y_rnhql1dhvdd44/T/pip-build-w4MwvS/networkx/networkx/algorithms/community/kclique.pyts      @