From 78920c9b51b3c20b869cb84484aeb49a44f3e64d Mon Sep 17 00:00:00 2001 From: Costa Shulyupin Date: Tue, 7 Aug 2018 08:04:46 +0300 Subject: [PATCH] *reduce_graph --- srcxray.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/srcxray.py b/srcxray.py index 9184066..3cbde7e 100755 --- a/srcxray.py +++ b/srcxray.py @@ -281,12 +281,13 @@ def my_graph(name=None): return g -def reduce_graph(g): +def reduce_graph(g, m=None): rm = set() - for e in g: - if not g.out_degree(e): - rm.add(e) + m = g.number_of_nodes() if not m else m + print(g.number_of_edges()) + rm = [n for (n, d) in g.out_degree if not d and g.in_degree(n) <= m] g.remove_nodes_from(rm) + print(g.number_of_edges()) return g