in agent/knowledge_graph.py [0:0]
def shortest_path(self, start_location, end_location, path=[]):
""" Find the shortest path between start and end locations. """
if start_location == end_location:
return path
if start_location not in self._out_graph:
return None
shortest = None
for connection in self._out_graph[start_location]:
if connection not in path:
newpath = self.shortest_path(connection.to_location,
end_location,
path + [connection])
if newpath:
if not shortest or len(newpath) < len(shortest):
shortest = newpath
return shortest