MCPcopy Index your code
hub / github.com/clips/pattern / shortest_path

Method shortest_path

pattern/graph/__init__.py:430–442  ·  view source on GitHub ↗

Returns a list of nodes connecting the two nodes.

(self, node1, node2, heuristic=None, directed=False)

Source from the content-addressed store, hash-verified

428 return [[self[id] for id in p] for p in paths(self, node1.id, node2.id, length, path)]
429
430 def shortest_path(self, node1, node2, heuristic=None, directed=False):
431 """ Returns a list of nodes connecting the two nodes.
432 """
433 if not isinstance(node1, Node):
434 node1 = self[node1]
435 if not isinstance(node2, Node):
436 node2 = self[node2]
437 try:
438 p = dijkstra_shortest_path(self, node1.id, node2.id, heuristic, directed)
439 p = [self[id] for id in p]
440 return p
441 except IndexError:
442 return None
443
444 def shortest_paths(self, node, heuristic=None, directed=False):
445 """ Returns a dictionary of nodes, each linked to a list of nodes (shortest path).

Callers 3

similarityMethod · 0.80
test_pathsMethod · 0.80
01-graph.pyFile · 0.80

Calls 1

dijkstra_shortest_pathFunction · 0.85

Tested by 1

test_pathsMethod · 0.64