Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
sklearn
/
utils
/
__pycache__
/
File Content:
graph.cpython-35.pyc
��(X_ � @ s� d Z d d l Z d d l m Z d d l m Z d d l m Z d d d � Z e e d � rl e j Z n d d l m Z d d d d � Z d d d d � Z d d d d � Z d S)zy Graph utilities and algorithms Graphs are represented with their adjacency matrices, preferably using sparse matrices. � N)�sparse� )�check_array)�graph_shortest_pathc C s� t j | � r | j � } n t j | � } i } d } | g } xw | r� | } t � } x8 | D]0 } | | k ra | | | <| j | j | � qa W| d k r� | | k r� P| d 7} qE W| S)a� 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 : node label 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]]) >>> single_source_shortest_path_length(graph, 0) {0: 0, 1: 1, 2: 2, 3: 3} >>> single_source_shortest_path_length(np.ones((6, 6)), 2) {0: 1, 1: 1, 2: 0, 3: 1, 4: 1, 5: 1} r Nr )r � isspmatrixZtolilZ lil_matrix�set�updateZrows)�graph�source�cutoff�seen�levelZ next_levelZ this_level�v� r � /graph.py�"single_source_shortest_path_length s"