我正在使用python多处理来创建多个不同的NetworkX图,然后使用下面的函数来组合图.但是,虽然此函数适用于小图形,但对于较大的图形,它使用大量内存并挂在我的系统和内存繁重的AWS系统上(仅占系统总内存的三分之一).有没有更有效的方法来执行以下功能?
def combine_graphs(graph1, graph2, graph2_weight = 1):
'''
Given two graphs of different edge (but same node) structure (and the same type),
combine the two graphs, summing all edge attributes and multiplying the second one's
attributes by the desired weights.
E.g. if graph1.edge[a][b] = {'a': 1, 'b':2} and
graph2.edge[a][b] = {'a': 3, 'c': 4},
with a weight of 1 the final graph edge should be
final_graph.edge[a][b] = {'a': 4, 'b': 2, 'c': 4} and with a weight
of .5 the …Run Code Online (Sandbox Code Playgroud)