def get_paths_of_length(self, source, num_hops=1):
""" Searchs for all nodes that are `num_hops` away.
Returns:
list of paths: A list of all shortest paths that have length
`num_hops + 1`
"""
# return a dictionary keyed by targets
# with a list of nodes in a shortest path
# from the source to one of the targets.
all_paths = networkx.shortest_path(self.graph, source)
return [
path
for path in all_paths.values()
if len(path) == num_hops + 1
]
评论列表
文章目录