Revision fac6e5a4 globecomm/main.py

View differences:

globecomm/main.py
2 2
from os.path import isfile, join, splitext, basename
3 3
import sys
4 4
import networkx as nx
5
import numpy
5 6

  
6 7
sys.path.append("heuristic_bc/")
7 8
from heuristic_betweenness_centrality import HeuristicBetweennessCentrality as HBC
8 9

  
9 10
from pdb import set_trace as debugger
10 11

  
11

  
12
GRAPH_DIRS='/home/quynh/Thesis/quynhnguyen-ms/experiment_input_graphs/CNGraphs/snapshots'
13 12
def get_all_files_from_dir(dir):
14 13
    return [join(dir, f) for f in listdir(dir) if isfile(join(dir, f))]
15 14

  
16 15

  
17 16
if __name__ == '__main__':
18
    onlyfiles = get_all_files_from_dir(GRAPH_DIRS)
17
    input_dir = ''
18
    # Default input directory
19
    GRAPH_DIRS='/home/quynh/Thesis/quynhnguyen-ms/experiment_input_graphs/CNGraphs/snapshots/small_samples'
20

  
21
    if len(sys.argv) > 1:
22
        input_dir = sys.argv[1]
23
    else:
24
        input_dir = GRAPH_DIRS
25

  
26
    onlyfiles = get_all_files_from_dir(input_dir)
19 27

  
20 28
    for in_filepath in onlyfiles:
21 29
        filename = splitext(basename(in_filepath))[0]
22 30
        graph = nx.read_weighted_edgelist(in_filepath)
23
        hbc = HBC(graph)
24 31
        out_filepath = join('output/', filename + '.hbcout')
25
        hbc.write(out_filepath)
32

  
33
        # Brandes BC
34
        bbc = nx.betweenness_centrality(graph, weight=True, normalized=True, endpoints=True)
35
        out_data = [[k, v] for (k, v) in bbc.iteritems()]
36
        numpy.savetxt(out_filepath, out_data, delimiter=',', fmt='%s')
37
        print "Finish calculating BC for %s" % filename
38

  
39
        # # Heuristic BC
40
        # hbc = HBC(graph)
41
        # hbc.write(out_filepath)
26 42

  
27 43

  
28 44

  

Also available in: Unified diff