Statistics
| Branch: | Revision:

root / fiddle / heuristic-betweenness-centrality / visualize.py @ 82c7c698

History | View | Annotate | Download (866 Bytes)

1 82c7c698 Quynh PX Nguyen
import os
2
import networkx as nx
3
import utility
4
5
MAIN_CODE_DIR = os.environ.get('MAIN_CODE_DIR', '')
6
7
def visualize_all_inputs(input_dir):
8
    files = list()
9
    # Find all the inputs with .edges
10
    for file in os.listdir(input_dir):
11
        if file.endswith('.edges'):
12
            files.append(file)
13
14
    output_dir = os.path.join(MAIN_CODE_DIR, 'output/visualization')
15
    output_suffix = ".png"
16
17
    for file in files:
18
        filepath = os.path.join(input_dir, file)
19
        graph = nx.read_weighted_edgelist(filepath)
20
21
        filename = os.path.splitext(os.path.basename(file))[0]
22
        output_path = os.path.join(output_dir, filename + output_suffix)
23
24
        utility.plot_graph(output_path, graph, title=filepath)
25
26
27
if __name__ == '__main__':
28
    utility.initialize()
29
    input_dir = os.path.join(MAIN_CODE_DIR, 'input')
30
    visualize_all_inputs(input_dir)