ó
‡ˆ\c           @   s€   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d „ Z	 e d ƒ d	 „  ƒ Z
 e d
 ƒ d „  ƒ Z d S(   sy   
Graph utilities and algorithms

Graphs are represented with their adjacency matrices, preferably using
sparse matrices.
iÿÿÿÿ(   t   sparse(   t   csgraphi   (   t   graph_shortest_path(   t
   deprecatedc         C   sÆ   t  j |  ƒ r |  j ƒ  }  n t  j |  ƒ }  i  } d } | g } x} | rÁ | } t ƒ  } x; | D]3 } | | k ra | | | <| j |  j | ƒ qa qa W| d k	 r´ | | k r´ Pn  | d 7} qE W| S(   sï  Return the shortest path length from source to all reachable nodes.

    Returns a dictionary of shortest path lengths keyed by target.

    Parameters
    ----------
    graph : sparse matrix or 2D array (preferably LIL matrix)
        Adjacency matrix of the graph
    source : integer
       Starting node for path
    cutoff : integer, optional
        Depth to stop the search - only
        paths of length <= cutoff are returned.

    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, 1],
    ...                   [ 0, 0, 1, 0]])
    >>> list(sorted(single_source_shortest_path_length(graph, 0).items()))
    [(0, 0), (1, 1), (2, 2), (3, 3)]
    >>> graph = np.ones((6, 6))
    >>> list(sorted(single_source_shortest_path_length(graph, 2).items()))
    [(0, 1), (1, 1), (2, 0), (3, 1), (4, 1), (5, 1)]
    i    i   N(   R    t
   isspmatrixt   tolilt
   lil_matrixt   sett   updatet   rowst   None(   t   grapht   sourcet   cutofft   seent   levelt
   next_levelt
   this_levelt   v(    (    s2   lib/python2.7/site-packages/sklearn/utils/graph.pyt"   single_source_shortest_path_length   s"    			
s›   sklearn.utils.graph.connected_components was deprecated in version 0.19 and will be removed in 0.21. Use scipy.sparse.csgraph.connected_components instead.c          O   s   t  j |  | Ž  S(   N(   R   t   connected_components(   t   argst   kwargs(    (    s2   lib/python2.7/site-packages/sklearn/utils/graph.pyR   I   s    s‹   sklearn.utils.graph.graph_laplacian was deprecated in version 0.19 and will be removed in 0.21. Use scipy.sparse.csgraph.laplacian instead.c          O   s   t  j |  | Ž  S(   N(   R   t	   laplacian(   R   R   (    (    s2   lib/python2.7/site-packages/sklearn/utils/graph.pyt   graph_laplacianP   s    N(   t   __doc__t   scipyR    t   scipy.sparseR   R   t   deprecationR   R
   R   R   R   (    (    (    s2   lib/python2.7/site-packages/sklearn/utils/graph.pyt   <module>   s   1