ó
 ,µ[c        @   @   sˆ   d  Z  d d l m Z d d l m Z d j d d g ƒ Z d g Z d- Z d. Z	 d( „  e
 e ƒ Dƒ Z d) „  Z e d* ƒ d+ „  ƒ Z d, S(/   s*   Functions for analyzing triads of a graph.iÿÿÿÿ(   t   division(   t   not_implemented_fors   
s%   Alex Levenson (alex@isnontinvain.com)s9   Diederik van Liere (diederik.vanliere@rotman.utoronto.ca)t   triadic_censusi   i   i   i   i   i   i   i   i   i	   i   i
   i   i   i   i   t   003t   012t   102t   021Dt   021Ut   021Ct   111Dt   111Ut   030Tt   030Ct   201t   120Dt   120Ut   120Ct   210t   300c         C   s'   i  |  ] \ } } t  | d  | “ q S(   i   (   t   TRIAD_NAMES(   t   .0t   it   code(    (    s9   lib/python2.7/site-packages/networkx/algorithms/triads.pys
   <dictcomp>%   s   	 c            sh   | | d f | | d f | | d f | | d f | | d f | | d f f } t  ‡  f d †  | Dƒ ƒ S(   sñ   Returns the integer code of the given triad.

    This is some fancy magic that comes from Batagelj and Mrvar's paper. It
    treats each edge joining a pair of `v`, `u`, and `w` as a bit in
    the binary representation of an integer.

    i   i   i   i   i   i    c         3   s.   |  ]$ \ } } } | ˆ  | k r | Vq d  S(   N(    (   R   t   ut   vt   x(   t   G(    s9   lib/python2.7/site-packages/networkx/algorithms/triads.pys	   <genexpr>2   s    (   t   sum(   R   R   R   t   wt   combos(    (   R   s9   lib/python2.7/site-packages/networkx/algorithms/triads.pyt   _tricode(   s    <t
   undirectedc   
      C   sô  d „  t  Dƒ } t |  ƒ } d „  t |  ƒ Dƒ } x|  D]…} t |  j | ƒ t |  j | ƒ B} xX| D]P} | | | | k rŠ qj n  | t |  j | ƒ Bt |  j | ƒ B| | h } | |  | k rı | |  | k rı | d c | t | ƒ d 7<n | d c | t | ƒ d 7<xœ | D]” } | | | | k  sŠ| | | | k  o_| | k  n r"| |  j | k r"| |  j | k r"t |  | | | ƒ }	 | t |	 c d 7<q"q"Wqj Wq9 W| | d | d d t | j	 ƒ  ƒ | d <| S(	   s'  Determines the triadic census of a directed graph.

    The triadic census is a count of how many of the 16 possible types of
    triads are present in a directed graph.

    Parameters
    ----------
    G : digraph
       A NetworkX DiGraph

    Returns
    -------
    census : dict
       Dictionary with triad names as keys and number of occurrences as values.

    Notes
    -----
    This algorithm has complexity $O(m)$ where $m$ is the number of edges in
    the graph.

    See also
    --------
    triad_graph

    References
    ----------
    .. [1] Vladimir Batagelj and Andrej Mrvar, A subquadratic triad census
        algorithm for large sparse networks with small maximum degree,
        University of Ljubljana,
        http://vlado.fmf.uni-lj.si/pub/networks/doc/triads/triads.pdf

    c         S   s   i  |  ] } d  | “ q S(   i    (    (   R   t   name(    (    s9   lib/python2.7/site-packages/networkx/algorithms/triads.pys
   <dictcomp>X   s   	 c         S   s   i  |  ] \ } } | | “ q S(    (    (   R   R   R   (    (    s9   lib/python2.7/site-packages/networkx/algorithms/triads.pys
   <dictcomp>[   s   	 R   i   R   i   i   R   (
   R   t   lent	   enumeratet   sett   predt   succR   t   TRICODE_TO_NAMER   t   values(
   R   t   censust   nt   mR   t   vnbrsR   t	   neighborsR   R   (    (    s9   lib/python2.7/site-packages/networkx/algorithms/triads.pyR   5   s(    #$2 !<#.N(@   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i	   i	   i   i   i
   i	   i   i   i   i   i   i   i   i   i   i   i	   i
   i   i   i	   i	   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   (   R   R   R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   (   t   __doc__t
   __future__R    t   networkx.utilsR   t   joint
   __author__t   __all__t   TRICODESR   R"   R&   R   R   (    (    (    s9   lib/python2.7/site-packages/networkx/algorithms/triads.pyt   <module>   s   		    	