MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / dfs

Method dfs

numpy_ml/utils/graphs.py:233–249  ·  view source on GitHub ↗

A simple DFS helper routine

(v_i, path=None)

Source from the content-addressed store, hash-verified

231 visited = set()
232
233 def dfs(v_i, path=None):
234 """A simple DFS helper routine"""
235 path = set([v_i]) if path is None else path
236 for nbr_i in self.get_neighbors(v_i):
237 if nbr_i in path:
238 return True # cycle detected!
239 elif nbr_i not in visited:
240 visited.add(nbr_i)
241 path.add(nbr_i)
242 is_cyclic = dfs(nbr_i, path)
243 if is_cyclic:
244 return True
245
246 # insert to the beginning of the ordering
247 ordering.insert(0, v_i)
248 path -= set([v_i])
249 return False
250
251 for s_i in self.indices:
252 if s_i not in visited:

Callers

nothing calls this directly

Calls 1

get_neighborsMethod · 0.80

Tested by

no test coverage detected