当前位置: 首页>>代码示例>>Python>>正文


Python Graph.copy方法代码示例

本文整理汇总了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
开发者ID:makslevental,项目名称:clrs,代码行数:34,代码来源:flownetworks.py

示例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!"
开发者ID:chinhodado,项目名称:CSI4105-Project,代码行数:14,代码来源:test_random_graphs.py

示例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
开发者ID:makslevental,项目名称:clrs,代码行数:24,代码来源:allpairs.py

示例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()
开发者ID:Twiddledidlydum,项目名称:BIGDIVE2-exercises,代码行数:19,代码来源:testnetworkX.py


注:本文中的networkx.Graph.copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。