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


Python networkx.OrderedGraph方法代码示例

本文整理汇总了Python中networkx.OrderedGraph方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.OrderedGraph方法的具体用法?Python networkx.OrderedGraph怎么用?Python networkx.OrderedGraph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx的用法示例。


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

示例1: test_tuplelabels

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_tuplelabels(self):
        # https://github.com/networkx/networkx/pull/1048
        # Writing tuple labels to GML failed.
        G = nx.OrderedGraph()
        G.add_edge((0, 1), (1, 0))
        data = '\n'.join(nx.generate_gml(G, stringizer=literal_stringizer))
        answer = """graph [
  node [
    id 0
    label "(0,1)"
  ]
  node [
    id 1
    label "(1,0)"
  ]
  edge [
    source 0
    target 1
  ]
]"""
        assert_equal(data, answer) 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:test_gml.py

示例2: test_differential_operator

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_differential_operator(self, n_vertices=98):
        r"""The Laplacian must always be the divergence of the gradient,
        whether the Laplacian is combinatorial or normalized, and whether the
        graph is directed or weighted."""
        def test_incidence_nx(graph):
            r"""Test that the incidence matrix corresponds to NetworkX."""
            incidence_pg = np.sign(graph.D.toarray())
            G = nx.OrderedDiGraph if graph.is_directed() else nx.OrderedGraph
            graph_nx = nx.from_scipy_sparse_matrix(graph.W, create_using=G)
            incidence_nx = nx.incidence_matrix(graph_nx, oriented=True)
            np.testing.assert_equal(incidence_pg, incidence_nx.toarray())
        for graph in [graphs.Graph(np.zeros((n_vertices, n_vertices))),
                      graphs.Graph(np.identity(n_vertices)),
                      graphs.Graph([[0, 0.8], [0.8, 0]]),
                      graphs.Graph([[1.3, 0], [0.4, 0.5]]),
                      graphs.ErdosRenyi(n_vertices, directed=False, seed=42),
                      graphs.ErdosRenyi(n_vertices, directed=True, seed=42)]:
            for lap_type in ['combinatorial', 'normalized']:
                graph.compute_laplacian(lap_type)
                graph.compute_differential_operator()
                L = graph.D.dot(graph.D.T)
                np.testing.assert_allclose(L.toarray(), graph.L.toarray())
                test_incidence_nx(graph) 
开发者ID:epfl-lts2,项目名称:pygsp,代码行数:25,代码来源:test_graphs.py

示例3: test_reversed

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_reversed(self):
        C33 = nx.OrderedGraph()
        C33.add_nodes_from(reversed(range(3*3*4)))
        C33.add_edges_from(dnx.chimera_graph(3, 3, 4).edges)
        coord = chimera_coordinates(3, 3, 4)

        labels = canonical_chimera_labeling(C33)
        labels = {v: coord.chimera_to_linear(labels[v]) for v in labels}

        G = nx.relabel_nodes(C33, labels, copy=True)

        self.assertTrue(nx.is_isomorphic(G, C33)) 
开发者ID:dwavesystems,项目名称:dwave_networkx,代码行数:14,代码来源:test_canonicalization.py

示例4: busmap_by_linemask

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def busmap_by_linemask(network, mask):
    mask = network.lines.loc[:,['bus0', 'bus1']].assign(mask=mask).set_index(['bus0','bus1'])['mask']
    G = nx.OrderedGraph()
    G.add_nodes_from(network.buses.index)
    G.add_edges_from(mask.index[mask])
    return pd.Series(OrderedDict((n, str(i))
                                 for i, g in enumerate(nx.connected_components(G))
                                 for n in g),
                     name='name') 
开发者ID:PyPSA,项目名称:PyPSA,代码行数:11,代码来源:networkclustering.py

示例5: test_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_graph():
        G = nx.OrderedGraph() 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:4,代码来源:test_ordered.py

示例6: test_write_edgelist_1

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_write_edgelist_1(self):
        fh = io.BytesIO()
        G = nx.OrderedGraph()
        G.add_edges_from([(1, 2), (2, 3)])
        nx.write_edgelist(G, fh, data=False)
        fh.seek(0)
        assert_equal(fh.read(), b"1 2\n2 3\n") 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_edgelist.py

示例7: test_write_edgelist_2

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_write_edgelist_2(self):
        fh = io.BytesIO()
        G = nx.OrderedGraph()
        G.add_edges_from([(1, 2), (2, 3)])
        nx.write_edgelist(G, fh, data=True)
        fh.seek(0)
        assert_equal(fh.read(), b"1 2 {}\n2 3 {}\n") 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_edgelist.py

示例8: test_write_edgelist_3

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_write_edgelist_3(self):
        fh = io.BytesIO()
        G = nx.OrderedGraph()
        G.add_edge(1, 2, weight=2.0)
        G.add_edge(2, 3, weight=3.0)
        nx.write_edgelist(G, fh, data=True)
        fh.seek(0)
        assert_equal(fh.read(), b"1 2 {'weight': 2.0}\n2 3 {'weight': 3.0}\n") 
开发者ID:holzschu,项目名称:Carnets,代码行数:10,代码来源:test_edgelist.py

示例9: test_write_edgelist_4

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_write_edgelist_4(self):
        fh = io.BytesIO()
        G = nx.OrderedGraph()
        G.add_edge(1, 2, weight=2.0)
        G.add_edge(2, 3, weight=3.0)
        nx.write_edgelist(G, fh, data=[('weight')])
        fh.seek(0)
        assert_equal(fh.read(), b"1 2 2.0\n2 3 3.0\n") 
开发者ID:holzschu,项目名称:Carnets,代码行数:10,代码来源:test_edgelist.py

示例10: test_attribute_dict_integrity

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_attribute_dict_integrity(self):
        # we must not replace dict-like graph data structures with dicts
        G = nx.OrderedGraph()
        G.add_nodes_from("abc")
        H = to_networkx_graph(G, create_using=nx.OrderedGraph)
        assert_equal(list(H.nodes), list(G.nodes))
        H = nx.OrderedDiGraph(G)
        assert_equal(list(H.nodes), list(G.nodes)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:10,代码来源:test_convert.py

示例11: test_subgraph_copy

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_subgraph_copy(self):
        for origG in self.graphs:
            G = nx.OrderedGraph(origG)
            SG = G.subgraph([4, 5, 6])
            H = SG.copy()
            assert_equal(type(G), type(H)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:8,代码来源:test_graphviews.py

示例12: test_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_graph(self):
        G = nx.OrderedGraph() 
开发者ID:holzschu,项目名称:Carnets,代码行数:4,代码来源:test_ordered.py

示例13: test_graph1

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_graph1(self):
        G = nx.OrderedGraph([
            (3, 10), (2, 13), (1, 13), (7, 11), (0, 8), (8, 13), (0, 2),
            (0, 7), (0, 10), (1, 7)
        ])
        self.check_graph(G, is_planar=True) 
开发者ID:holzschu,项目名称:Carnets,代码行数:8,代码来源:test_planarity.py

示例14: test_graph2

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_graph2(self):
        G = nx.OrderedGraph([
            (1, 2), (4, 13), (0, 13), (4, 5), (7, 10), (1, 7), (0, 3), (2, 6),
            (5, 6), (7, 13), (4, 8), (0, 8), (0, 9), (2, 13), (6, 7), (3, 6),
            (2, 8)
        ])
        self.check_graph(G, is_planar=False) 
开发者ID:holzschu,项目名称:Carnets,代码行数:9,代码来源:test_planarity.py

示例15: test_write_edgelist_1

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import OrderedGraph [as 别名]
def test_write_edgelist_1(self):
        fh=io.BytesIO()
        G=nx.OrderedGraph()
        G.add_edges_from([(1,2),(2,3)])
        nx.write_edgelist(G,fh,data=False)
        fh.seek(0)
        assert_equal(fh.read(),b"1 2\n2 3\n") 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:9,代码来源:test_edgelist.py


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