當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。