§
    rŠtjR  ã            
       óÂ   — d Z ddlZddlmZ ddlmZ ddlmZm	Z	m
Z
  e
ddg e	eddd¬	¦  «        g e	eddd¬	¦  «        dgd
œd¬¦  «        ddœd„¦   «         Z	 	 dd„ZdS )zGraph utilities and algorithms.é    N)Úsparse)Úpairwise_distances)ÚIntegralÚIntervalÚvalidate_paramsz
array-likezsparse matrixÚleft)Úclosed)ÚgraphÚsourceÚcutoffT)Úprefer_skip_nested_validation)r   c                ó.  — t          j        | ¦  «        r|                      ¦   «         } nt          j        | ¦  «        } i }d}|g}|rN|}t	          ¦   «         }|D ]+}||vr%|||<   |                     | j        |         ¦  «         Œ,|�||k    rn|dz  }|°N|S )aD  Return the length of the shortest path from source to all reachable nodes.

    Parameters
    ----------
    graph : {array-like, sparse matrix} of shape (n_nodes, n_nodes)
        Adjacency matrix of the graph. Sparse matrix of format LIL is
        preferred.

    source : int
       Start node for path.

    cutoff : int, default=None
        Depth to stop the search - only paths of length <= cutoff are returned.

    Returns
    -------
    paths : dict
        Reachable end nodes mapped to length of path from source,
        i.e. `{end: path_length}`.

    Examples
    --------
    >>> from sklearn.utils.graph import single_source_shortest_path_length
    >>> import numpy as np
    >>> graph = np.array([[ 0, 1, 0, 0],
    ...                   [ 1, 0, 1, 0],
    ...                   [ 0, 1, 0, 0],
    ...                   [ 0, 0, 0, 0]])
    >>> single_source_shortest_path_length(graph, 0)
    {0: 0, 1: 1, 2: 2}
    >>> graph = np.ones((6, 6))
    >>> sorted(single_source_shortest_path_length(graph, 2).items())
    [(0, 1), (1, 1), (2, 0), (3, 1), (4, 1), (5, 1)]
    r   Né   )r   ÚissparseÚtolilÚ	lil_arrayÚsetÚupdateÚrows)r
   r   r   ÚseenÚlevelÚ
next_levelÚ
this_levelÚvs           úQ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/utils/graph.pyÚ"single_source_shortest_path_lengthr      sÄ   € õV „�uÑÔð (Ø—’‘”ˆˆåÔ  Ñ'Ô'ˆØ€DØ€EØ�€JØ
ð 	Øˆ
Ý‘U”Uˆ
Øð 	1ð 	1ˆAØ˜ˆ}ˆ}Ø��Q‘Ø×!Ò! %¤*¨Q¤-Ñ0Ô0Ð0øØÐ &¨E¢/ /ØØ�‰
ˆð ð 	ð €Kó    ÚdistanceÚ	euclideanc                 óâ  — |dk    r#t          j        | ¦  «        rt          d¦  «        ‚t          |¦  «        D �]4}t	          j        ||k    ¦  «        }| |         }	t          |¦  «        D �] }
t	          j        ||
k    ¦  «        }| |         }|dk    r| t	          j        ||¦  «                 }nt          |	|fd|i|¤Ž}t	          j        | 	                    d¬¦  «        |j
        ¦  «        \  }}|dk    r'd|||         ||         f<   d|||         ||         f<   Œ³|dk    r7|||f         |||         ||         f<   |||f         |||         ||         f<   Œðt          d	|z  ¦  «        ‚�Œ6|S )
a   Add connections to sparse graph to connect unconnected components.

    For each pair of unconnected components, compute all pairwise distances
    from one component to the other, and add a connection on the closest pair
    of samples. This is a hacky way to get a graph with a single connected
    component, which is necessary for example to compute a shortest path
    between all pairs of samples in the graph.

    Parameters
    ----------
    X : array of shape (n_samples, n_features) or (n_samples, n_samples)
        Features to compute the pairwise distances. If `metric =
        "precomputed"`, X is the matrix of pairwise distances.

    graph : sparse matrix of shape (n_samples, n_samples)
        Graph of connection between samples.

    n_connected_components : int
        Number of connected components, as computed by
        `scipy.sparse.csgraph.connected_components`.

    component_labels : array of shape (n_samples)
        Labels of connected components, as computed by
        `scipy.sparse.csgraph.connected_components`.

    mode : {'connectivity', 'distance'}, default='distance'
        Type of graph matrix: 'connectivity' corresponds to the connectivity
        matrix with ones and zeros, and 'distance' corresponds to the distances
        between neighbors according to the given metric.

    metric : str
        Metric used in `sklearn.metrics.pairwise.pairwise_distances`.

    kwargs : kwargs
        Keyword arguments passed to
        `sklearn.metrics.pairwise.pairwise_distances`.

    Returns
    -------
    graph : sparse matrix of shape (n_samples, n_samples)
        Graph of connection between samples, with a single connected component.
    ÚprecomputedzŒ_fix_connected_components with metric='precomputed' requires the full distance matrix in X, and does not work with a sparse neighbors graph.ÚmetricN)ÚaxisÚconnectivityr   r   z?Unknown mode=%r, should be one of ['connectivity', 'distance'].)r   r   ÚRuntimeErrorÚrangeÚnpÚflatnonzeroÚix_r   Úunravel_indexÚargminÚshapeÚ
ValueError)ÚXr
   Ún_connected_componentsÚcomponent_labelsÚmoder"   ÚkwargsÚiÚidx_iÚXiÚjÚidx_jÚXjÚDÚiiÚjjs                   r   Ú_fix_connected_componentsr<   O   s·  € ðf �ÒÐ¥6¤?°1Ñ#5Ô#5ÐÝðñ
ô 
ð 	
õ Ð)Ñ*Ô*ð ñ ˆÝ”Ð/°1Ò4Ñ5Ô5ˆØˆuŒXˆÝ�q‘”ð 	ñ 	ˆAÝ”NÐ#3°qÒ#8Ñ9Ô9ˆEØ�5”ˆBà˜Ò&Ð&Ø•b”f˜U EÑ*Ô*Ô+��å& r¨2ÐGÐG°fÐGÀÐGÐG�åÔ% a§h¢h°D hÑ&9Ô&9¸1¼7ÑCÔC‰FˆB�Ø�~Ò%Ð%Ø./��e˜B”i  r¤Ð*Ñ+Ø./��e˜B”i  r¤Ð*Ñ+Ð+Ø˜Ò#Ð#Ø./°°B°¬i��e˜B”i  r¤Ð*Ñ+Ø./°°B°¬i��e˜B”i  r¤Ð*Ñ+Ð+å ØUØññô ð ñ#	ð, €Lr   )r   r   )Ú__doc__Únumpyr'   Úscipyr   Úsklearn.metrics.pairwiser   Úsklearn.utils._param_validationr   r   r   r   r<   © r   r   ú<module>rC      s  ðØ %Ð %ð
 Ð Ð Ð Ø Ð Ð Ð Ð Ð à 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OÐ Oð €à Ð0Ø�8˜H a¨°fÐ=Ñ=Ô=Ð>Ø�8˜H a¨°fÐ=Ñ=Ô=¸tÐDðð ð
 #'ðñ ô ð AEð 4ð 4ð 4ð 4ñô ð4ðx 
ØðSð Sð Sð Sð Sð Sr   