Revision 27b1b922

View differences:

simulator.py
63 63
                '''bw_centrality = nx.betweenness_centrality(G, normalized=False,  weight='weight', endpoints=True)'''
64 64
                #code.interact(local=dict(globals(), **locals()))
65 65
                import graph_tool.centrality as gtc
66
                gtG = nx2gt.nx2gt(G)
67
                ws=gtG.edge_properties["weight"]
68
                vp, ep = gtc.betweenness(gtG, norm=False, weight=ws)
66
                #print "Convertig nxG to graph_tool Graph..."
67
                #gtG = nx2gt.nx2gt(G)
68
                ws=G.edge_properties["weight"]
69
                #print "Computing BC with graph_tool..."
70
                vp, ep = gtc.betweenness(G, norm=False, weight=ws)
71
                #print "Writing BC to disk..."
69 72
                btw = {i: vp.a[i] for i in range(len(vp.a))}
70 73
                df = pd.DataFrame(btw.items(), columns=['Node', 'BC'])
71 74
                df.to_csv(self.OP+"/BC"+tag+".csv", sep=',',
util/UnitDiskGraph.py
10 10

  
11 11
    def __init__(self, points, radius):
12 12
        self.G = nx.Graph()
13
        self.G.add_nodes_from(range(len(points)))
14
        '''
13
        #self.G.add_nodes_from(range(len(points)))
14
        
15 15
        self.G = gt.Graph(directed=False)
16 16
        self.G.add_vertex(len(points))
17
        self.edge_weights = self.G.new_edge_property('double')
18
        self.G.edge_properties['weight'] = self.edge_weights'''
17
        self.edge_weights = self.G.new_edge_property('float')
18
        #self.G.edge_properties['weight'] = self.edge_weights
19 19
        
20 20
        self.generateGraphCDIST(points, radius)
21 21
        
......
39 39
                if r==c:
40 40
                    continue
41 41
                if distM[r][c] <= radius:
42
                    edges.append((r,c,1.0))
43
        self.G.add_weighted_edges_from(edges, weight='weight')
44
        '''code.interact(local=dict(globals(), **locals()))
45
        for e in edges:
42
                    edges.append([r,c, 1.0])
43
        #self.G.add_weighted_edges_from(edges, weight='weight')
44
        #code.interact(local=dict(globals(), **locals()))
45
        self.G.ep["weight"] = self.G.new_edge_property("float")
46
        eprops = [self.G.ep["weight"]]
47
        self.G.add_edge_list(edges, hashed=True, eprops=eprops)
48
        #self.G.add_edge_list(edges, eprops=self.edge_weights)
49
        '''for e in edges:
46 50
            e = self.G.add_edge(e[0],e[1])
47 51
            self.edge_weights[e] = 1.0'''
48 52

  

Also available in: Unified diff