Revision 3c6ce57c fiddle/heuristic-betweenness-centrality/utility.py

View differences:

fiddle/heuristic-betweenness-centrality/utility.py
1 1
import os
2 2
import networkx as nx
3
import betweenness_centrality as centrality
3 4

  
4 5
MAIN_CODE_DIR = os.environ.get('MAIN_CODE_DIR', '')
5 6

  
7
def weight_betweenness_centrality(filepath, file_suffix):
8
    graph = nx.read_weighted_edgelist(filepath)
9

  
10
    score = centrality.weight_betweenness_centrality(graph, rescale=True)
11
    filepath = '/output/weight_basic_%s.csv'  % file_suffix
12

  
13
    with open(MAIN_CODE_DIR + filepath, 'w') as output:
14
        for node, bc in score.iteritems():
15
            output.write('%s, %s\n' % (node, bc))
16

  
6 17
def brandes_betweenness_centrality(filepath, file_suffix):
7 18
    graph = nx.read_weighted_edgelist(filepath)
8 19

  
9
    score = nx.betweenness_centrality(graph, endpoints=True)
20
    score = nx.betweenness_centrality(graph)
10 21
    filepath = '/output/networkx_%s.csv'  % file_suffix
11 22

  
12 23
    with open(MAIN_CODE_DIR + filepath, 'w') as output:
13
        for node, centrality in score.iteritems():
14
            output.write('%s, %s\n' % (node, centrality))
24
        for node, bc in score.iteritems():
25
            output.write('%s, %s\n' % (node, bc))
26

  
27
def brandes_betweenness_centrality_endpoints(filepath, file_suffix):
28
    graph = nx.read_weighted_edgelist(filepath)
29

  
30
    score = nx.betweenness_centrality(graph, endpoints=True)
31
    filepath = '/output/heuristic_%s.csv'  % file_suffix
32

  
33
    with open(MAIN_CODE_DIR + filepath, 'w') as output:
34
        for node, bc in score.iteritems():
35
            output.write('%s, %s\n' % (node, bc))

Also available in: Unified diff