def correctLoops(code, loops_graph, charge_type):
while nx.cycle_basis(loops_graph) != []:
cycle = nx.cycle_basis(loops_graph)[0]
loop = path.Path(cycle)
for data in code.Primal.nodes():
if loop.contains_points([data]) == [True]:
charge = code.Primal.node[data]['charge'][charge_type]
code.Primal.node[data]['charge'][charge_type] = (charge + 1)%2
l = len(cycle)
for i in range(l):
n1, n2 = cycle[i], cycle[(i+1)%l]
loops_graph.remove_edge(*(n1,n2))
return code, loops_graph
评论列表
文章目录