§
    bŠtj	  ã                   ó8   — d Z ddlZdgZej        d„ ¦   «         ZdS )z(Function for computing walks in a graph.é    NÚnumber_of_walksc                 ó
  ‡ ‡— ddl }|dk     rt          d|› �¦  «        ‚t          j        ‰ d¬¦  «        }|j        j                             ||¦  «                             ¦   «         Šˆ ˆfd„t          ‰ ¦  «        D ¦   «         }|S )aß  Returns the number of walks connecting each pair of nodes in `G`

    A *walk* is a sequence of nodes in which each adjacent pair of nodes
    in the sequence is adjacent in the graph. A walk can repeat the same
    edge and go in the opposite direction just as people can walk on a
    set of paths, but standing still is not counted as part of the walk.

    This function only counts the walks with `walk_length` edges. Note that
    the number of nodes in the walk sequence is one more than `walk_length`.
    The number of walks can grow very quickly on a larger graph
    and with a larger walk length.

    Parameters
    ----------
    G : NetworkX graph

    walk_length : int
        A nonnegative integer representing the length of a walk.

    Returns
    -------
    dict
        A dictionary of dictionaries in which outer keys are source
        nodes, inner keys are target nodes, and inner values are the
        number of walks of length `walk_length` connecting those nodes.

    Raises
    ------
    ValueError
        If `walk_length` is negative

    Examples
    --------

    >>> G = nx.Graph([(0, 1), (1, 2)])
    >>> walks = nx.number_of_walks(G, 2)
    >>> walks
    {0: {0: 1, 1: 0, 2: 1}, 1: {0: 0, 1: 2, 2: 0}, 2: {0: 1, 1: 0, 2: 1}}
    >>> total_walks = sum(sum(tgts.values()) for _, tgts in walks.items())

    You can also get the number of walks from a specific source node using the
    returned dictionary. For example, number of walks of length 1 from node 0
    can be found as follows:

    >>> walks = nx.number_of_walks(G, 1)
    >>> walks[0]
    {0: 0, 1: 1, 2: 0}
    >>> sum(walks[0].values())  # walks from 0 of length 1
    1

    Similarly, a target node can also be specified:

    >>> walks[0][1]
    1

    r   Nz"`walk_length` cannot be negative: )Úweightc                 óR   •‡— i | ]"\  Š}|ˆˆfd „t          ‰¦  «        D ¦   «         “Œ#S )c                 óP   •— i | ]"\  }}|‰‰|f                               ¦   «         “Œ#S © )Úitem)Ú.0Úv_idxÚvÚpowerÚu_idxs      €€úW/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/algorithms/walks.pyú
<dictcomp>z.number_of_walks.<locals>.<dictcomp>.<dictcomp>J   s4   ø€ ÐGÐGÐG©h¨e°QˆAˆu�U˜E�\Ô"×'Ò'Ñ)Ô)ÐGÐGÐGó    )Ú	enumerate)r
   Úur   ÚGr   s     @€€r   r   z#number_of_walks.<locals>.<dictcomp>I   sN   øø€ ð ð ð áˆE�1ð 	
ÐGÐGÐGÐGÐG½)ÀA¹,¼,ÐGÑGÔGðð ð r   )	ÚscipyÚ
ValueErrorÚnxÚadjacency_matrixÚsparseÚlinalgÚmatrix_powerÚtocsrr   )r   Úwalk_lengthÚspÚAÚresultr   s   `    @r   r   r      s¨   øø€ ðt ÐÐÐà�Q‚€ÝÐK¸kÐKÐKÑLÔLÐLå
Ô˜A dÐ+Ñ+Ô+€AØŒIÔ×)Ò)¨!¨[Ñ9Ô9×?Ò?ÑAÔA€Eðð ð ð ð å! !™œðñ ô €Fð €Mr   )Ú__doc__Únetworkxr   Ú__all__Ú_dispatchabler   r   r   r   ú<module>r%      sM   ðØ .Ð .à Ð Ð Ð àÐ
€ð ÔðDð Dñ ÔðDð Dð Dr   