*digraph_tree
This commit is contained in:
parent
ea71d924f3
commit
9768c13793
|
@ -419,7 +419,7 @@ def digraph_tree(dg, starts=None):
|
||||||
def sub(node):
|
def sub(node):
|
||||||
tree.add_node(node)
|
tree.add_node(node)
|
||||||
for o in dg.successors(node):
|
for o in dg.successors(node):
|
||||||
if o in black_list or tree.has_edge(node, o):
|
if o in black_list or tree.has_node(o):
|
||||||
continue
|
continue
|
||||||
tree.add_edge(node,o)
|
tree.add_edge(node,o)
|
||||||
sub(o)
|
sub(o)
|
||||||
|
@ -430,11 +430,13 @@ def digraph_tree(dg, starts=None):
|
||||||
for i in [n for (n, d) in dg.in_degree if not d]:
|
for i in [n for (n, d) in dg.in_degree if not d]:
|
||||||
starts[i] = dg.out_degree(i)
|
starts[i] = dg.out_degree(i)
|
||||||
starts = [a[0] for a in sorted(starts.items(), key=lambda k: k[1], reverse=True)]
|
starts = [a[0] for a in sorted(starts.items(), key=lambda k: k[1], reverse=True)]
|
||||||
if len(starts) > 1:
|
if len(starts) == 1:
|
||||||
o.add_node('starts')
|
sub(starts[0])
|
||||||
|
elif len(starts) > 1:
|
||||||
for o in starts:
|
for o in starts:
|
||||||
if o in black_list:
|
if o in black_list:
|
||||||
continue
|
continue
|
||||||
|
tree.add_edge('start',o)
|
||||||
sub(o)
|
sub(o)
|
||||||
return tree
|
return tree
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue