§
    bŠtjÇ   ã                   óD  — d Z ddlmZ ddlmZ ddlmZ ddlZddl	m
Z
 ddlmZ g d	¢Zej        d
„ ¦   «         Zd„ Z e
d¦  «         e
d¦  «        ej        d„ ¦   «         ¦   «         ¦   «         Z e
d¦  «         e
d¦  «        ej        d„ ¦   «         ¦   «         ¦   «         ZdS )zI
=======================
Distance-regular graphs
=======================
é    )Údefaultdict)Úcombinations_with_replacement)ÚlogN)Únot_implemented_foré   )Údiameter)Úis_distance_regularÚis_strongly_regularÚintersection_arrayÚglobal_parametersc                 óR   — 	 t          | ¦  «         dS # t          j        $ r Y dS w xY w)a  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

    TF)r   ÚnxÚNetworkXError©ÚGs    úb/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/algorithms/distance_regular.pyr	   r	      s@   € ðRÝ˜1ÑÔÐØˆtøÝÔð ð ð Øˆuˆuðøøøs   ‚ “&¥&c                 óL   ‡ — ˆ fd„t          ‰ dgz   dg|z   ¦  «        D ¦   «         S )a“  Returns global parameters for a given intersection array.

    Given a distance-regular graph G with diameter d and 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 : list

    c : list

    Returns
    -------
    iterable
       An iterable over 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
    c              3   ó@   •K  — | ]\  }}|‰d          |z
  |z
  |fV — ŒdS )r   N© )Ú.0ÚxÚyÚbs      €r   ú	<genexpr>z$global_parameters.<locals>.<genexpr>q   s:   øè è € ÐCÐC¡T Q¨ˆQ��!”�q‘˜1‘˜aÐ ÐCÐCÐCÐCÐCÐCó    r   )Úzip)r   Úcs   ` r   r   r   H   s7   ø€ ðR DÐCÐCÐC­S°°a°S±¸1¸#À¹'Ñ-BÔ-BÐCÑCÔCÐCr   ÚdirectedÚ
multigraphc                 óš  ‡‡‡‡— t          j        | ¦  «        rt          j        | ¦  «        st          j        d¦  «        ‚t	          t
          ¦  «        }i Ši Šd}dt          t          | ¦  «        d¦  «        z  dz  }t          | d¦  «        D �]‡\  }}||         Š|‰vrM‰ 	                    t          j
        | |¦  «        ¦  «         ‰                     ¦   «         D ]\  }}|||         |<   Œ||         |         Št          |‰¦  «        }||k    rt          j        d¦  «        ‚| |         }|D ][}	||	         }
||
vrM|
 	                    t          j
        | |	¦  «        ¦  «         |
                     ¦   «         D ]\  }}|||         |	<   ŒŒ\t          ˆˆfd„|D ¦   «         ¦  «        }t          ˆˆfd„|D ¦   «         ¦  «        }‰                     ‰|¦  «        |k    s‰                     ‰|¦  «        |k    rt          j        d¦  «        ‚|‰‰<   |‰‰<   �Œ‰ˆfd	„t          |¦  «        D ¦   «         ˆfd
„t          |¦  «        D ¦   «         fS )a�  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's intersection 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
    zGraph is not distance regular.r   é   é   é   c              3   ó:   •K  — | ]}‰|         ‰d z
  k    ¯d V — ŒdS ©r   Nr   ©r   ÚnÚiÚpl_us     €€r   r   z%intersection_array.<locals>.<genexpr>Ë   ó5   øè è € Ð5Ð5�a D¨¤G¨q°1©uÒ$4Ð$4�Ð$4Ð$4Ð$4Ð$4Ð5Ð5r   c              3   ó:   •K  — | ]}‰|         ‰d z   k    ¯d V — ŒdS r%   r   r&   s     €€r   r   z%intersection_array.<locals>.<genexpr>Í   r*   r   zGraph is not distance regularc                 ó<   •— g | ]}‰                      |d ¦  «        ‘ŒS )r   ©Úget)r   ÚjÚbints     €r   ú
<listcomp>z&intersection_array.<locals>.<listcomp>Õ   s%   ø€ Ð-Ð-Ð-˜Aˆ�Š�!�Q‰ŒÐ-Ð-Ð-r   c                 óB   •— g | ]}‰                      |d z   d¦  «        ‘ŒS )r   r   r-   )r   r/   Úcints     €r   r1   z&intersection_array.<locals>.<listcomp>Ö   s+   ø€ Ð1Ð1Ð1 ˆ�Š�!�a‘%˜Ñ	Ô	Ð1Ð1Ð1r   )r   Ú
is_regularÚis_connectedr   r   Údictr   Úlenr   ÚupdateÚ"single_source_shortest_path_lengthÚitemsÚmaxÚsumr.   Úrange)r   Úpath_lengthÚdiamÚmax_diameter_for_dr_graphsÚuÚvr   ÚdistanceÚvnbrsr'   Úpl_nr   r   r0   r3   r(   r)   s                @@@@r   r   r   t   sŒ  øøøø€ õd Œ=˜ÑÔð A¥2¤?°1Ñ#5Ô#5ð AÝÔÐ?Ñ@Ô@Ð@å�dÑ#Ô#€KØ€DØ€Dð
 €DØ"#¥c­#¨a©&¬&°!¡n¤nÑ"4¸Ñ!9ÐÝ-¨a°Ñ3Ô3ð  ñ  ‰ˆˆ1à˜1Œ~ˆØ�Dˆ=ˆ=Ø�KŠK�Ô=¸aÀÑCÔCÑDÔDÐDØ#Ÿzšz™|œ|ð -ð -‘��8Ø$,�˜A”˜qÑ!Ð!à˜ŒN˜1ÔˆÝ�4˜‰|Œ|ˆð Ð,Ò,Ð,ÝÔ"Ð#CÑDÔDÐDà�!”ˆàð 	1ð 	1ˆAØ˜q”>ˆDØ˜ˆ}ˆ}Ø—’�BÔAÀ!ÀQÑGÔGÑHÔHÐHØ#'§:¢:¡<¤<ð 1ð 1‘K�A�xØ(0�K ”N 1Ñ%Ð%øõ Ð5Ð5Ð5Ð5Ð5˜5Ð5Ñ5Ô5Ñ5Ô5ˆåÐ5Ð5Ð5Ð5Ð5˜5Ð5Ñ5Ô5Ñ5Ô5ˆà�8Š8�A�q‰>Œ>˜QÒÐ $§(¢(¨1¨a¡.¤.°AÒ"5Ð"5ÝÔ"Ð#BÑCÔCÐCØˆˆQ‰ØˆˆQ‰‰ð 	.Ð-Ð-Ð-¥ t¡¤Ð-Ñ-Ô-Ø1Ð1Ð1Ð1¥U¨4¡[¤[Ð1Ñ1Ô1ðð r   c                 óF   — t          | ¦  «        ot          | ¦  «        dk    S )a  Returns True if and only if the given graph is strongly
    regular.

    An undirected graph is *strongly regular* if

    * it is regular,
    * each pair of adjacent vertices has the same number of neighbors in
      common,
    * each pair of nonadjacent vertices has the same number of neighbors
      in common.

    Each strongly regular graph is a distance-regular graph.
    Conversely, if a distance-regular graph has diameter two, then it is
    a strongly regular graph. For more information on distance-regular
    graphs, see :func:`is_distance_regular`.

    Parameters
    ----------
    G : NetworkX graph
        An undirected graph.

    Returns
    -------
    bool
        Whether `G` is strongly regular.

    Examples
    --------

    The cycle graph on five vertices is strongly regular. It is
    two-regular, each pair of adjacent vertices has no shared neighbors,
    and each pair of nonadjacent vertices has one shared neighbor::

        >>> G = nx.cycle_graph(5)
        >>> nx.is_strongly_regular(G)
        True

    r"   )r	   r   r   s    r   r
   r
   Û   s#   € õj ˜qÑ!Ô!Ð6¥h¨q¡k¤k°QÒ&6Ð6r   )Ú__doc__Úcollectionsr   Ú	itertoolsr   Úmathr   Únetworkxr   Únetworkx.utilsr   Údistance_measuresr   Ú__all__Ú_dispatchabler	   r   r   r
   r   r   r   ú<module>rP      s_  ððð ð $Ð #Ð #Ð #Ð #Ð #Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .à 'Ð 'Ð 'Ð 'Ð 'Ð 'ðð ð €ð Ôð,ð ,ñ Ôð,ð^)Dð )Dð )DðX Ð�ZÑ Ô ØÐ�\Ñ"Ô"ØÔð`ð `ñ Ôñ #Ô"ñ !Ô ð`ðH Ð�ZÑ Ô ØÐ�\Ñ"Ô"ØÔð27ð 27ñ Ôñ #Ô"ñ !Ô ð27ð 27ð 27r   