ó
ú£Õ\c           @   sS   d  d l  m Z d  d l Z d j d d g ƒ Z d g Z d d „ Z d „  Z	 d S(	   iÿÿÿÿ(   t   defaultdictNs   
s    Conrad Lee <conradlee@gmail.com>s%   Aric Hagberg <aric.hagberg@gmail.com>t   k_clique_communitiesc   
      c   sR  | d k  r" t  j d | ƒ ‚ n  | d k r@ t  j |  ƒ } n  g  | D]$ } t | ƒ | k rG t | ƒ ^ qG } t t ƒ } x0 | D]( } x | D] } | | j | ƒ q‘ Wq„ Wt  j	 ƒ  } | j
 | ƒ xZ | D]R } xI t | | ƒ D]8 } t | j | ƒ ƒ | d k ræ | j | | ƒ qæ qæ WqÐ Wx% t  j | ƒ D] }	 t j |	 Œ  Vq6Wd S(   s#  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
    --------
    >>> G = nx.complete_graph(5)
    >>> K5 = nx.convert_node_labels_to_integers(G,first_label=2)
    >>> G.add_edges_from(K5.edges())
    >>> c = list(nx.k_clique_communities(G, 4))
    >>> list(c[0])
    [0, 1, 2, 3, 4, 5, 6]
    >>> list(nx.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
    i   s   k=%d, k must be greater than 1.i   N(   t   nxt   NetworkXErrort   Nonet   find_cliquest   lent	   frozensetR    t   listt   appendt   Grapht   add_nodes_fromt   _get_adjacent_cliquest   intersectiont   add_edget   connected_componentst   union(
   t   Gt   kt   cliquest   ct   membership_dictt   cliquet   nodet
   perc_grapht
   adj_cliquet	   component(    (    s]   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/community/kclique.pyR      s"    &1c         C   sO   t  ƒ  } x? |  D]7 } x. | | D]" } |  | k r! | j | ƒ q! q! Wq W| S(   N(   t   sett   add(   R   R   t   adjacent_cliquest   nR   (    (    s]   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/community/kclique.pyR   L   s    	(
   t   collectionsR    t   networkxR   t   joint
   __author__t   __all__R   R   R   (    (    (    s]   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/community/kclique.pyt   <module>   s   		?