3
Md	                 @   s0   d dl mZ d dlZdgZdddZdd ZdS )    )defaultdictNk_clique_communitiesc       	      #   s    dk rt jd  d|dkr,t j| } fdd|D }tt}x(|D ] }x|D ]}|| j| qVW qLW t j }|j| xB|D ]:}x4t||D ]&}t	|j
| d kr|j|| qW qW xt j|D ]}tj| V  qW dS )ue  Find 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))
    >>> sorted(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
       zk=z, k must be greater than 1.Nc                s    g | ]}t | krt|qS  )len	frozenset).0c)kr   W/var/www/html/virt/lib/python3.6/site-packages/networkx/algorithms/community/kclique.py
<listcomp>2   s    z(k_clique_communities.<locals>.<listcomp>   )nxZNetworkXErrorZfind_cliquesr   listappendZGraphZadd_nodes_from_get_adjacent_cliquesr   intersectionZadd_edgeZconnected_componentsr   union)	Gr
   Zcliquesmembership_dictcliquenodeZ
perc_graph
adj_clique	componentr   )r
   r   r      s"    '




c             C   s<   t  }x0| D ](}x"|| D ]}| |kr|j| qW qW |S )N)setadd)r   r   Zadjacent_cliquesnr   r   r   r   r   H   s    
r   )N)collectionsr   Znetworkxr   __all__r   r   r   r   r   r   <module>   s   
A