def dfs_postorder(self, root):
G = nx.Graph(self.E)
tree_graph = nx.dfs_tree(G,root)
clique_ordering = list(nx.dfs_postorder_nodes(tree_graph,root))
return clique_ordering
python类dfs_tree()的实例源码
def main():
func_list = parse.parse(open(sys.argv[1]).read())
G = foo(func_list)
#G = callgraph(func_list)
nx.write_dot(G,"G.dot")
#H = nx.dfs_tree(G,'solver')
#nx.write_dot(H,"H.dot")
#print nx.topological_sort(H)
def _trim_subtree(self, tree, root):
"""Trims off and returns a subtree rooted at root. Updates all
necessary internal state.
:param tree:
:type tree: nx.DiGraph
:param root:
:return: subtree rooted at root
"""
subtree = nx.dfs_tree(tree, root)
self._update_bookkeeping(subtree, root)
tree.remove_nodes_from(subtree.nodes())
return subtree