• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python networkx.add_path函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中networkx.add_path函数的典型用法代码示例。如果您正苦于以下问题:Python add_path函数的具体用法?Python add_path怎么用?Python add_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了add_path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_all_simple_paths_multigraph

def test_all_simple_paths_multigraph():
    G = nx.MultiGraph([(1, 2), (1, 2)])
    paths = nx.all_simple_paths(G, 1, 1)
    assert_equal(paths, [])
    nx.add_path(G, [3, 1, 10, 2])
    paths = nx.all_simple_paths(G, 1, 2)
    assert_equal(set(tuple(p) for p in paths), {(1, 2), (1, 2), (1, 10, 2)})
开发者ID:wkschwartz,项目名称:networkx,代码行数:7,代码来源:test_simple_paths.py


示例2: test_bidirectional_dijkstra_ignore

def test_bidirectional_dijkstra_ignore():
    G = nx.Graph()
    nx.add_path(G, [1, 2, 10])
    nx.add_path(G, [1, 3, 10])
    assert_raises(
        nx.NetworkXNoPath,
        _bidirectional_dijkstra,
        G,
        1, 2,
        ignore_nodes=[1],
    )
    assert_raises(
        nx.NetworkXNoPath,
        _bidirectional_dijkstra,
        G,
        1, 2,
        ignore_nodes=[2],
    )
    assert_raises(
        nx.NetworkXNoPath,
        _bidirectional_dijkstra,
        G,
        1, 2,
        ignore_nodes=[1, 2],
    )
开发者ID:ProgVal,项目名称:networkx,代码行数:25,代码来源:test_simple_paths.py


示例3: test_preflow_push_makes_enough_space

def test_preflow_push_makes_enough_space():
    #From ticket #1542
    G = nx.DiGraph()
    nx.add_path(G, [0, 1, 3], capacity=1)
    nx.add_path(G, [1, 2, 3], capacity=1)
    R = preflow_push(G, 0, 3, value_only=False)
    assert_equal(R.graph['flow_value'], 1)
开发者ID:iaciac,项目名称:networkx,代码行数:7,代码来源:test_maxflow.py


示例4: test_edges_with_data_not_equal

 def test_edges_with_data_not_equal(self):
     G = nx.MultiGraph()
     nx.add_path(G, [0, 1, 2], weight=1)
     H = nx.MultiGraph()
     nx.add_path(H, [0, 1, 2], weight=2)
     self._test_not_equal(G.edges(data=True, keys=True),
                          H.edges(data=True, keys=True))
开发者ID:4c656554,项目名称:networkx,代码行数:7,代码来源:test_utils.py


示例5: setUp

 def setUp(self):
     #
     #       -- s1 --
     #     /     |    \
     #   c1-----c2----c3
     #  /  \   / | \    \
     # r1  r2 r3 r4 r5  r6
     #
     topo = fnss.Topology()
     icr_candidates = ["c1", "c2", "c3"]
     nx.add_path(topo, icr_candidates)
     topo.add_edge("c1", "s1")
     topo.add_edge("c2", "s1")
     topo.add_edge("c3", "s1")
     topo.add_edge("c1", "r1")
     topo.add_edge("c1", "r2")
     topo.add_edge("c2", "r3")
     topo.add_edge("c2", "r4")
     topo.add_edge("c2", "r5")
     topo.add_edge("c3", "r6")
     topo.graph['icr_candidates'] = set(icr_candidates)
     for router in icr_candidates:
         fnss.add_stack(topo, router, 'router')
     for src in ['s1']:
         fnss.add_stack(topo, src, 'source')
     for rcv in ['r1', 'r2', 'r3', 'r4', 'r5', 'r6']:
         fnss.add_stack(topo, rcv, 'receiver')
     self.topo = cacheplacement.IcnTopology(topo)
开发者ID:icarus-sim,项目名称:icarus,代码行数:28,代码来源:test_cacheplacement.py


示例6: test_barbell

def test_barbell():
    G = nx.barbell_graph(8, 4)
    nx.add_path(G, [7, 20, 21, 22])
    nx.add_cycle(G, [22, 23, 24, 25])
    pts = set(nx.articulation_points(G))
    assert_equal(pts, {7, 8, 9, 10, 11, 12, 20, 21, 22})

    answer = [
        {12, 13, 14, 15, 16, 17, 18, 19},
        {0, 1, 2, 3, 4, 5, 6, 7},
        {22, 23, 24, 25},
        {11, 12},
        {10, 11},
        {9, 10},
        {8, 9},
        {7, 8},
        {21, 22},
        {20, 21},
        {7, 20},
    ]
    assert_components_equal(list(nx.biconnected_components(G)), answer)

    G.add_edge(2,17)
    pts = set(nx.articulation_points(G))
    assert_equal(pts, {7, 20, 21, 22})
开发者ID:AmesianX,项目名称:networkx,代码行数:25,代码来源:test_biconnected.py


示例7: nrr_topology

 def nrr_topology(cls):
     """Return topology for testing NRR caching strategies
     """
     # Topology sketch
     #
     # 0 ---- 2----- 4
     #        |       \
     #        |        s
     #        |       /
     # 1 ---- 3 ---- 5
     #
     topology = IcnTopology(fnss.Topology())
     nx.add_path(topology, [0, 2, 4, "s", 5, 3, 1])
     topology.add_edge(2, 3)
     receivers = (0, 1)
     source = "s"
     caches = (2, 3, 4, 5)
     contents = (1, 2, 3, 4)
     fnss.add_stack(topology, source, 'source', {'contents': contents})
     for v in caches:
         fnss.add_stack(topology, v, 'router', {'cache_size': 1})
     for v in receivers:
         fnss.add_stack(topology, v, 'receiver', {})
     fnss.set_delays_constant(topology, 1, 'ms')
     return topology
开发者ID:icarus-sim,项目名称:icarus,代码行数:25,代码来源:test_offpath.py


示例8: test_notarborescence2

def test_notarborescence2():
    # Not an arborescence due to in-degree violation.
    G = nx.MultiDiGraph()
    nx.add_path(G, range(5))
    G.add_edge(6, 4)
    assert_false(nx.is_branching(G))
    assert_false(nx.is_arborescence(G))
开发者ID:4c656554,项目名称:networkx,代码行数:7,代码来源:test_recognition.py


示例9: test_not_connected

def test_not_connected():
    G = nx.Graph()
    nx.add_path(G, [1, 2, 3])
    nx.add_path(G, [4, 5])
    for interface_func in [nx.minimum_edge_cut, nx.minimum_node_cut]:
        for flow_func in flow_funcs:
            assert_raises(nx.NetworkXError, interface_func, G, flow_func=flow_func)
开发者ID:nishnik,项目名称:networkx,代码行数:7,代码来源:test_cuts.py


示例10: test_path

 def test_path(self):
     path = list(range(10))
     shuffle(path)
     G = nx.Graph()
     nx.add_path(G, path)
     for method in self._methods:
         order = nx.spectral_ordering(G, method=method)
         ok_(order in [path, list(reversed(path))])
开发者ID:4c656554,项目名称:networkx,代码行数:8,代码来源:test_algebraic_connectivity.py


示例11: compare_graph_paths_names

 def compare_graph_paths_names(g, paths, names):
     expected = nx.DiGraph()
     for p in paths:
         nx.add_path(expected, p)
     assert_equal(sorted(expected.nodes), sorted(g.nodes))
     assert_equal(sorted(expected.edges()), sorted(g.edges()))
     g_names = [g.get_edge_data(s, e)['Name'] for s, e in g.edges()]
     assert_equal(names, sorted(g_names))
开发者ID:iaciac,项目名称:networkx,代码行数:8,代码来源:test_shp.py


示例12: test_P5_multiple_target

 def test_P5_multiple_target(self):
     """Betweenness centrality: P5 multiple target"""
     G = nx.Graph()
     nx.add_path(G, range(5))
     b_answer = {0: 0, 1: 1, 2: 1, 3: 0.5, 4: 0, 5: 0}
     b = nx.betweenness_centrality_subset(G, sources=[0], targets=[3, 4],
                                          weight=None)
     for n in sorted(G):
         assert_almost_equal(b[n], b_answer[n])
开发者ID:ProgVal,项目名称:networkx,代码行数:9,代码来源:test_betweenness_centrality_subset.py


示例13: test_weighted

 def test_weighted(self):
     G = nx.Graph()
     nx.add_cycle(G, range(7), weight=2)
     ans = nx.average_shortest_path_length(G, weight='weight')
     assert_almost_equal(ans, 4)
     G = nx.Graph()
     nx.add_path(G, range(5), weight=2)
     ans = nx.average_shortest_path_length(G, weight='weight')
     assert_almost_equal(ans, 4)
开发者ID:jianantian,项目名称:networkx,代码行数:9,代码来源:test_generic.py


示例14: test_P5

 def test_P5(self):
     """Betweenness Centrality Subset: P5"""
     G = nx.Graph()
     nx.add_path(G, range(5))
     b_answer = {0: 0, 1: 0.5, 2: 0.5, 3: 0, 4: 0, 5: 0}
     b = nx.betweenness_centrality_subset(G, sources=[0], targets=[3],
                                          weight=None)
     for n in sorted(G):
         assert_almost_equal(b[n], b_answer[n])
开发者ID:networkx,项目名称:networkx,代码行数:9,代码来源:test_betweenness_centrality_subset.py


示例15: setUp

 def setUp(self):
     deg=[3,2,2,1,0]
     self.G=havel_hakimi_graph(deg)
     self.P=nx.path_graph(3)
     self.WG=nx.Graph( (u,v,{'weight':0.5,'other':0.3})
             for (u,v) in self.G.edges() )
     self.WG.add_node(4)
     self.DG=nx.DiGraph()
     nx.add_path(self.DG, [0,1,2])
开发者ID:4c656554,项目名称:networkx,代码行数:9,代码来源:test_spectrum.py


示例16: setUp

 def setUp(self):
     self.P4=nx.path_graph(4)
     self.D=nx.DiGraph()
     self.D.add_edges_from([(0, 2), (0, 3), (1, 3), (2, 3)])
     self.M=nx.MultiGraph()
     nx.add_path(self.M, range(4))
     self.M.add_edge(0,1)
     self.S=nx.Graph()
     self.S.add_edges_from([(0,0),(1,1)])
开发者ID:4c656554,项目名称:networkx,代码行数:9,代码来源:base_test.py


示例17: test_not_connected

def test_not_connected():
    G = nx.Graph()
    nx.add_path(G, [1, 2, 3])
    nx.add_path(G, [4, 5])
    for flow_func in flow_funcs:
        assert_equal(nx.node_connectivity(G), 0,
                     msg=msg.format(flow_func.__name__))
        assert_equal(nx.edge_connectivity(G), 0,
                     msg=msg.format(flow_func.__name__))
开发者ID:AmesianX,项目名称:networkx,代码行数:9,代码来源:test_connectivity.py


示例18: test_directed_path_normalized

 def test_directed_path_normalized(self):
     """Betweenness centrality: directed path normalized"""
     G=nx.DiGraph()
     nx.add_path(G, [0, 1, 2])
     b=nx.betweenness_centrality(G,
                                       weight=None,
                                       normalized=True)
     b_answer={0: 0.0, 1: 0.5, 2: 0.0}
     for n in sorted(G):
         assert_almost_equal(b[n],b_answer[n])
开发者ID:4c656554,项目名称:networkx,代码行数:10,代码来源:test_betweenness_centrality.py


示例19: test_path

 def test_path(self):
     # based on setupClass numpy is installed if we get here
     from numpy.random import shuffle
     path = list(range(10))
     shuffle(path)
     G = nx.Graph()
     nx.add_path(G, path)
     for method in self._methods:
         order = nx.spectral_ordering(G, method=method)
         ok_(order in [path, list(reversed(path))])
开发者ID:ProgVal,项目名称:networkx,代码行数:10,代码来源:test_algebraic_connectivity.py


示例20: test_all_pairs_connectivity_directed

 def test_all_pairs_connectivity_directed(self):
     G = nx.DiGraph()
     nodes = [0, 1, 2, 3]
     nx.add_path(G, nodes)
     A = {n: {} for n in G}
     for u, v in itertools.permutations(nodes, 2):
         A[u][v] = nx.node_connectivity(G, u, v)
     C = nx.all_pairs_node_connectivity(G)
     assert_equal(sorted((k, sorted(v)) for k, v in A.items()),
                  sorted((k, sorted(v)) for k, v in C.items()))
开发者ID:AmesianX,项目名称:networkx,代码行数:10,代码来源:test_connectivity.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python networkx.adj_matrix函数代码示例发布时间:2022-05-27
下一篇:
Python networkx.add_cycle函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap