ó
|£*^c           @   sU   d  Z  d d l Z d j d d g ƒ Z d d d g Z d	 „  Z d
 „  Z d „  Z d S(   sI   
=======================
Distance-regular graphs
=======================
iÿÿÿÿNs   
s"   Dheeraj M R <dheerajrav@gmail.com>s%   Aric Hagberg <aric.hagberg@gmail.com>t   is_distance_regulart   intersection_arrayt   global_parametersc         C   s0   y t  |  ƒ } t SWn t j k
 r+ t SXd S(   s!  Returns True if the graph is distance regular, False otherwise.

    A connected graph G is distance-regular if for any nodes x,y
    and any integers i,j=0,1,...,d (where d is the graph
    diameter), the number of vertices at distance i from x and
    distance j from y depends only on i,j and the graph distance
    between x and y, independently of the choice of x and y.

    Parameters
    ----------
    G: Networkx graph (undirected)

    Returns
    -------
    bool
      True if the graph is Distance Regular, False otherwise

    Examples
    --------
    >>> G=nx.hypercube_graph(6)
    >>> nx.is_distance_regular(G)
    True
    
    See Also
    --------
    intersection_array, global_parameters

    Notes
    -----
    For undirected and simple graphs only

    References
    ----------
    .. [1] Brouwer, A. E.; Cohen, A. M.; and Neumaier, A. 
        Distance-Regular Graphs. New York: Springer-Verlag, 1989.
    .. [2] Weisstein, Eric W. "Distance-Regular Graph." 
        http://mathworld.wolfram.com/Distance-RegularGraph.html

    N(   R   t   Truet   nxt   NetworkXErrort   False(   t   Gt   a(    (    sx   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/distance_regular.pyR       s
    (c   	      C   s„   t  |  ƒ } |  } | } | j d ƒ | j d d ƒ | d } g  t | | ƒ D] \ } } | | | ^ qQ } t | | | g Œ  S(   sm  Return global parameters for a given intersection array.

    Given a distance-regular graph G with integers b_i, c_i,i = 0,....,d
    such that for any 2 vertices x,y in G at a distance i=d(x,y), there
    are exactly c_i neighbors of y at a distance of i-1 from x and b_i
    neighbors of y at a distance of i+1 from x.
    
    Thus, a distance regular graph has the global parameters,
    [[c_0,a_0,b_0],[c_1,a_1,b_1],......,[c_d,a_d,b_d]] for the
    intersection array  [b_0,b_1,.....b_{d-1};c_1,c_2,.....c_d]
    where a_i+b_i+c_i=k , k= degree of every vertex.

    Parameters
    ----------
    b,c: tuple of lists 

    Returns
    -------
    p : list of three-tuples

    Examples
    --------
    >>> G=nx.dodecahedral_graph()
    >>> b,c=nx.intersection_array(G)
    >>> list(nx.global_parameters(b,c))
    [(0, 0, 3), (1, 0, 2), (1, 1, 1), (1, 1, 1), (2, 0, 1), (3, 0, 0)]

    References
    ----------
    .. [1] Weisstein, Eric W. "Global Parameters." 
       From MathWorld--A Wolfram Web Resource. 
       http://mathworld.wolfram.com/GlobalParameters.html 

    See Also
    --------
    intersection_array 
    i    (   t   lent   appendt   insertt   zip(	   t   bt   ct   dt   bat   cat   kt   xt   yt   aa(    (    sx   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/distance_regular.pyR   ?   s    &
0c         C   sK  |  j  ƒ  s |  j ƒ  r- t j d d ƒ ‚ n  |  j ƒ  } t | ƒ \ } } x8 | D]0 \ } } | | k r| t j d ƒ ‚ n  | } qR Wt j |  ƒ } t g  | D] } t | | j	 ƒ  ƒ ^ qŸ ƒ } i  } i  }	 x |  D]}
 x|  D]} y | |
 | } Wn  t
 k
 rt j d ƒ ‚ n Xt g  |  | D]$ } | | |
 | d k r-| ^ q-ƒ } t g  |  | D]$ } | | |
 | d k rh| ^ qhƒ } |	 j | | ƒ | k sÅ| j | | ƒ | k r×t j d ƒ ‚ n  | | | <| |	 | <qä Wq× Wg  t | ƒ D] } | j | d ƒ ^ q g  t | ƒ D] } |	 j | d d ƒ ^ q(f S(   s–  Returns the intersection array of a distance-regular graph.

    Given a distance-regular graph G with integers b_i, c_i,i = 0,....,d
    such that for any 2 vertices x,y in G at a distance i=d(x,y), there
    are exactly c_i neighbors of y at a distance of i-1 from x and b_i
    neighbors of y at a distance of i+1 from x.

    A distance regular graph'sintersection array is given by, 
    [b_0,b_1,.....b_{d-1};c_1,c_2,.....c_d]

    Parameters
    ----------
    G: Networkx graph (undirected)

    Returns
    -------
    b,c: tuple of lists 

    Examples
    --------
    >>> G=nx.icosahedral_graph()
    >>> nx.intersection_array(G)
    ([5, 2, 1], [1, 2, 5])

    References
    ----------
    .. [1] Weisstein, Eric W. "Intersection Array." 
       From MathWorld--A Wolfram Web Resource. 
       http://mathworld.wolfram.com/IntersectionArray.html
    

    See Also
    --------
    global_parameters
    s   Not implemented for directed s   or multiedge graphs.s   Graph is not distance regular.i   s   Graph is not distance regulari    (   t   is_multigrapht   is_directedR   t   NetworkxExceptiont   degree_itert   nextR   t   all_pairs_shortest_path_lengtht   maxt   valuest   KeyErrorR	   t   gett   range(   R   t   degreet   _R   t   knextt   path_lengtht   nt   diametert   bintt   cintt   ut   vt   iR   R   (    (    sx   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/distance_regular.pyR   o   s6    $	
/;;0
((	   t   __doc__t   networkxR   t   joint
   __author__t   __all__R    R   R   (    (    (    sx   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/distance_regular.pyt   <module>   s   		.	0