0
我目前正在审查一个工作系统,以确定可以优化的区域。我发现,在循环低于%左右,70在Python中更新容量igraph
for t in G.get_edgelist():
eid = G.get_eid(*t)
origin = G.vs[t[0]]['name']
destin = G.vs[t[1]]['name']
if fc.cpdict[origin]['node_type'] == 'dependency':
cp_func[nodes.index(destin)] *= cp_func[nodes.index(origin)]
cap = cp_func[nodes.index(origin)]
G.es[eid]["capacity"] = cap
系统需要更新,因为模型时最后一次迭代已经改变边缘的容量增加了运行时间。在why-is-add-edge-function-so-slow-ompared-to-add-edges答案状态
原因是igraph在C层中使用索引边界列表作为其数据结构。该索引使得可以在固定时间内查询特定顶点的邻居。如果图形很少发生变化,这很好,但是当修改操作比查询要频繁得多时,这会变成一种负担,因为每当添加或删除边缘时,都必须更新索引。
有没有更好的方法来做这个更新。