本文整理汇总了Python中networkx.Graph.edge[u][v]['flow']方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.edge[u][v]['flow']方法的具体用法?Python Graph.edge[u][v]['flow']怎么用?Python Graph.edge[u][v]['flow']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.Graph
的用法示例。
在下文中一共展示了Graph.edge[u][v]['flow']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edmondskarp
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import edge[u][v]['flow'] [as 别名]
def edmondskarp(G: nx.Graph, s, t):
RG = G.copy()
for u,v in G.edges_iter():
G.edge[u][v]['flow'] = 0
path = isthereapath(RG,s,t)
while len(path) > 0:
path_cp = min([RG.edge[u][v]['capacity'] for u,v in path])
for u,v in path:
if G.has_edge(u,v):
G.edge[u][v]['flow'] += path_cp
RG.edge[u][v]['capacity'] -= path_cp
if RG.edge[u][v]['capacity'] == 0:
RG.remove_edge(u,v)
if RG.has_edge(v,u):
RG.edge[v][u]['capacity'] += path_cp
else:
RG.add_edge(v,u,capacity=path_cp)
else:
# then this edge is a "cancelling" flow
# residue should go up and cancelling "capacity" should go down
G.edge[v][u]['flow'] -= path_cp
RG.edge[v][u]['capacity'] += path_cp
RG.edge[u][v]['capacity'] -= path_cp
if RG.edge[u][v]['capacity'] == 0:
RG.remove_edge(u,v)
path = isthereapath(RG,s,t)
return RG