-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyze.py
43 lines (36 loc) · 1.39 KB
/
analyze.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import sys
from typing import Iterator
from fas_graph import FASGraph
from feedback_arc_set import reduce_graph
from networkit_fas import NetworkitGraph
def expand_files(files: list[str]) -> Iterator[str]:
file_stack: list[str] = list(reversed(files))
while len(file_stack) > 0:
filename = file_stack.pop()
if os.path.isfile(filename):
yield filename
elif os.path.isdir(filename):
files = [
os.path.join(filename, file) for file in os.listdir(filename)
]
file_stack.extend(files)
def print_scc_stats(graph: FASGraph):
components = [
comp for comp in graph.iter_components() if comp.get_num_nodes() > 2
]
print(f"SCC: {len(components)}")
num_nodes_sorter = graph.__class__.get_num_nodes
max_graph = max(components, key=num_nodes_sorter)
max_nodes = max_graph.get_num_nodes()
max_edges = max_graph.get_num_edges()
print(f"maxSCC: {max_nodes} nodes, {max_edges} edges")
if __name__ == "__main__":
for filename in expand_files(sys.argv[1:]):
print(f"Reading input file {filename}")
graph, _labels = NetworkitGraph.load_from_adjacency_list(filename)
print(f"{graph.get_num_nodes()} nodes, {graph.get_num_edges()} edges")
print_scc_stats(graph)
reduce_graph(graph)
print("After reduction:")
print_scc_stats(graph)