2017-09-14 111 views
1

我想加快頂點/邊屬性訪問過程。graph_tool:訪問頂點/邊財產更快

頂點屬性訪問,我發現然而,對於邊緣屬性訪問優化的一種方式,也不是那麼微不足道的我。

的想法爲頂點屬性是直接修改內部陣列(a屬性)。

例如

vfilt = g.new_vertex_property('bool') 
for i in range(9999): 
    vfilt.a[int(i % n)] = random.randint(0, 1) 

(注意vfilt.avfilt

,而不是使用:

vfilt = g.new_vertex_property('bool') 
for i in range(9999): 
    vfilt[int(i % n)] = random.randint(0, 1) 

然而,對於邊緣,我不知道邊緣之間的映射它在屬性數組中的內部索引。

我的問題是:

  • 如何優化邊緣屬性訪問?
  • 有沒有其他的方法來優化頂點屬性?

回答

0

如何

for e in g.edges(): 
    vfilt[e] = random.randint(0, 1) 

同樣,對於頂點:

for v in g.vertices(): 
    vfilt[v] = random.randint(0, 1)