本文整理汇总了Python中networkx.Graph.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.copy方法的具体用法?Python Graph.copy怎么用?Python Graph.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.Graph
的用法示例。
在下文中一共展示了Graph.copy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edmondskarp
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import copy [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
示例2: test_algorithms
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import copy [as 别名]
def test_algorithms(algorithms, graph: nx.Graph):
print()
print("Testing graph with {0} nodes and {1} edges".format(graph.number_of_nodes(), graph.number_of_edges()))
results = []
for algorithm, name in algorithms:
# make a copy of the graph in case the algorithm mutates it
graph_copy = graph.copy()
start_time = time.time()
result = len(algorithm.get_fbvs(graph_copy))
print("{0}: {1}, time: {2}".format(name, result, time.time() - start_time))
results.append(result)
assert results.count(results[0]) == len(results), "The algorithms's results are not the same!"
示例3: johnson
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import copy [as 别名]
def johnson(G: nx.Graph):
Gp = G.copy()
Gp.add_node(-1)
Gp.add_edges_from([(-1,i,{'weight':0}) for i in range(len(G.node))])
D = bellmanford(Gp,-1)
DD = {}
if D:
h = len(Gp.node)*[None]
for v,d in Gp.nodes_iter(data=True):
h[v] = d['distance']
for u,v in Gp.edges_iter():
Gp.edge[u][v]['weight'] += (h[u] - h[v])
for u in G.node:
dijkstra(Gp,u)
for v,d in Gp.nodes_iter(data=True):
DD[(u,v)] = d['distance'] + h[v] - h[u]
return DD
示例4: Graph
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import copy [as 别名]
from networkx import Graph
entries = Graph()
#entries.add_node('@davidmartinb')
#entries.add_node('@emartinborregon')
entries.add_edge('@davidmartinb','@emartinborregon')
#entries.add
entries2 = entries.copy()
#entries.add_node('@davidmartinb')
#entries.add_node('@emartinborregon')
entries2.add_edge('@davidmartinb','@test')
entries.add_edge('@davidmartinb','@emartinborregon')
#entries.add
print set(entries2.nodes())-set(entries.nodes())
edges1=entries.edges()
entries2.remove_edges_from( edges1 )
print entries2.edges()