*reduce_graph

This commit is contained in:
Costa Shulyupin 2018-08-07 08:04:46 +03:00
parent 686b1f9553
commit 78920c9b51
1 changed files with 5 additions and 4 deletions

View File

@ -281,12 +281,13 @@ def my_graph(name=None):
return g return g
def reduce_graph(g): def reduce_graph(g, m=None):
rm = set() rm = set()
for e in g: m = g.number_of_nodes() if not m else m
if not g.out_degree(e): print(g.number_of_edges())
rm.add(e) rm = [n for (n, d) in g.out_degree if not d and g.in_degree(n) <= m]
g.remove_nodes_from(rm) g.remove_nodes_from(rm)
print(g.number_of_edges())
return g return g