當前位置: 首頁>>代碼示例>>Python>>正文


Python networkx.grid_graph方法代碼示例

本文整理匯總了Python中networkx.grid_graph方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.grid_graph方法的具體用法?Python networkx.grid_graph怎麽用?Python networkx.grid_graph使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在networkx的用法示例。


在下文中一共展示了networkx.grid_graph方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_3d_2x2x2_on_c2

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_3d_2x2x2_on_c2(self):
        embedding = find_grid_embedding([2, 2, 2], 2, 2, t=4)

        # should be 4 grids
        self.assertEqual(len(embedding), 2*2*2)

        target_adj = dwave.embedding.target_to_source(dnx.chimera_graph(2), embedding)

        G = nx.grid_graph(dim=[2, 2, 2])
        for u in G.adj:
            for v in G.adj[u]:
                self.assertIn(u, target_adj)
                self.assertIn(v, target_adj[u])

        for u in target_adj:
            for v in target_adj[u]:
                self.assertIn(u, G.adj)
                self.assertIn(v, G.adj[u]) 
開發者ID:dwavesystems,項目名稱:dwave-system,代碼行數:20,代碼來源:test_embedding_chimera.py

示例2: test_2d_6x4_on_c6

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_2d_6x4_on_c6(self):
        dims = [3, 2]
        chimera = (3,)

        embedding = find_grid_embedding(dims, *chimera)

        self.assertEqual(len(embedding), self.prod(dims))

        target_adj = dwave.embedding.target_to_source(dnx.chimera_graph(*chimera), embedding)

        G = nx.grid_graph(list(reversed(dims)))
        for u in G.adj:
            for v in G.adj[u]:
                self.assertIn(u, target_adj)
                self.assertIn(v, target_adj[u], "{} is not adjacent to {}".format(v, u))

        for u in target_adj:
            for v in target_adj[u]:
                self.assertIn(u, G.adj)
                self.assertIn(v, G.adj[u], "{} is not adjacent to {}".format(v, u)) 
開發者ID:dwavesystems,項目名稱:dwave-system,代碼行數:22,代碼來源:test_embedding_chimera.py

示例3: test_3d_4x4x4_on_c16

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_3d_4x4x4_on_c16(self):
        dims = [4, 4, 4]
        chimera = (16,)

        embedding = find_grid_embedding(dims, *chimera)

        self.assertEqual(len(embedding), self.prod(dims))

        target_adj = dwave.embedding.target_to_source(dnx.chimera_graph(*chimera), embedding)

        G = nx.grid_graph(dims)
        for u in G.adj:
            for v in G.adj[u]:
                self.assertIn(u, target_adj)
                self.assertIn(v, target_adj[u], "{} is not adjacent to {}".format(v, u))

        self.assertEqual(set(G.nodes), set(target_adj)) 
開發者ID:dwavesystems,項目名稱:dwave-system,代碼行數:19,代碼來源:test_embedding_chimera.py

示例4: test_grid_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_grid_graph(self):
        """grid_graph([n,m]) is a connected simple graph with the
        following properties:
        number_of_nodes = n*m
        degree_histogram = [0,0,4,2*(n+m)-8,(n-2)*(m-2)]
        """
        for n, m in [(3, 5), (5, 3), (4, 5), (5, 4)]:
            dim = [n, m]
            g = nx.grid_graph(dim)
            assert_equal(len(g), n * m)
            assert_equal(nx.degree_histogram(g), [0, 0, 4, 2 * (n + m) - 8,
                                                  (n - 2) * (m - 2)])

        for n, m in [(1, 5), (5, 1)]:
            dim = [n, m]
            g = nx.grid_graph(dim)
            assert_equal(len(g), n * m)
            assert_true(nx.is_isomorphic(g, nx.path_graph(5)))

#        mg = nx.grid_graph([n,m], create_using=MultiGraph())
#        assert_equal(mg.edges(), g.edges()) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:23,代碼來源:test_lattice.py

示例5: test_grid_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_grid_graph(self):
        """grid_graph([n,m]) is a connected simple graph with the
        following properties:
        number_of_nodes = n*m
        degree_histogram = [0,0,4,2*(n+m)-8,(n-2)*(m-2)]
        """
        for n, m in [(3, 5), (5, 3), (4, 5), (5, 4)]:
            dim = [n, m]
            g = nx.grid_graph(dim)
            assert_equal(len(g), n*m)
            assert_equal(nx.degree_histogram(g), [0, 0, 4, 2 * (n + m) - 8,
                                                  (n - 2) * (m - 2)])

        for n, m in [(1, 5), (5, 1)]:
            dim = [n, m]
            g = nx.grid_graph(dim)
            assert_equal(len(g), n*m)
            assert_true(nx.is_isomorphic(g, nx.path_graph(5)))

#        mg = nx.grid_graph([n,m], create_using=MultiGraph())
#        assert_equal(mg.edges(), g.edges()) 
開發者ID:aws-samples,項目名稱:aws-kube-codesuite,代碼行數:23,代碼來源:test_lattice.py

示例6: _gen_grid

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def _gen_grid(self, n):
        for _ in range(n):
            num_v = np.random.randint(self.min_num_v, self.max_num_v)
            assert num_v >= 4, 'We require a grid graph to contain at least two ' \
                                   'rows and two columns, thus 4 nodes, got {:d} ' \
                                   'nodes'.format(num_v)
            n_rows = np.random.randint(2, num_v // 2)
            n_cols = num_v // n_rows
            g = nx.grid_graph([n_rows, n_cols])
            g = nx.convert_node_labels_to_integers(g)
            self.graphs.append(g)
            self.labels.append(5) 
開發者ID:dmlc,項目名稱:dgl,代碼行數:14,代碼來源:minigc.py

示例7: grid

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def grid(start, dim=2, role_start=0):
    """ Builds a 2by2 grid
    """
    grid_G = nx.grid_graph([dim, dim])
    grid_G = nx.convert_node_labels_to_integers(grid_G, first_label=start)
    roles = [role_start for i in grid_G.nodes()]
    return grid_G, roles 
開發者ID:RexYing,項目名稱:gnn-model-explainer,代碼行數:9,代碼來源:synthetic_structsim.py

示例8: test_draw_chimera_embedding

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_draw_chimera_embedding(self):
        C = dnx.chimera_graph(4)
        G = nx.grid_graph([2, 3, 2])
        emb = {(0, 0, 0): [80, 48], (0, 0, 1): [50, 52], (0, 1, 0): [85, 93],
               (0, 1, 1): [84, 82], (0, 2, 0): [89], (0, 2, 1): [92],
               (1, 0, 0): [49, 54], (1, 0, 1): [83, 51], (1, 1, 0): [81],
               (1, 1, 1): [86, 94], (1, 2, 0): [87, 95], (1, 2, 1): [91]}
        dnx.draw_chimera_embedding(C, emb)
        dnx.draw_chimera_embedding(C, emb, embedded_graph=G)
        dnx.draw_chimera_embedding(C, emb, interaction_edges=C.edges()) 
開發者ID:dwavesystems,項目名稱:dwave_networkx,代碼行數:12,代碼來源:test_chimera_layout.py

示例9: test_draw_pegasus_embedding

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_draw_pegasus_embedding(self):
        P = dnx.pegasus_graph(2)
        G = nx.grid_graph([3, 3, 2])
        emb = {(0, 0, 0): [35], (0, 0, 1): [12], (0, 0, 2): [31], (0, 1, 0): [16],
               (0, 1, 1): [36], (0, 1, 2): [11], (0, 2, 0): [39], (0, 2, 1): [6],
               (0, 2, 2): [41], (1, 0, 0): [34], (1, 0, 1): [13], (1, 0, 2): [30],
               (1, 1, 0): [17], (1, 1, 1): [37], (1, 1, 2): [10], (1, 2, 0): [38],
               (1, 2, 1): [7], (1, 2, 2): [40]}
        dnx.draw_pegasus_embedding(P, emb)
        dnx.draw_pegasus_embedding(P, emb, embedded_graph=G)
        dnx.draw_pegasus_embedding(P, emb, interaction_edges=P.edges())
        dnx.draw_pegasus_embedding(P, emb, crosses=True) 
開發者ID:dwavesystems,項目名稱:dwave_networkx,代碼行數:14,代碼來源:test_pegasus_layout.py

示例10: test_naviable_small_world

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_naviable_small_world(self):
        G = nx.navigable_small_world_graph(5,p=1,q=0)
        gg = nx.grid_2d_graph(5,5).to_directed()
        assert_true(nx.is_isomorphic(G,gg))

        G = nx.navigable_small_world_graph(5,p=1,q=0,dim=3)
        gg = nx.grid_graph([5,5,5]).to_directed()
        assert_true(nx.is_isomorphic(G,gg))

        G = nx.navigable_small_world_graph(5,p=1,q=0,dim=1)
        gg = nx.grid_graph([5]).to_directed()
        assert_true(nx.is_isomorphic(G,gg)) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:14,代碼來源:test_geometric.py

示例11: test_navigable_small_world

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_navigable_small_world(self):
        G = nx.navigable_small_world_graph(5, p=1, q=0, seed=42)
        gg = nx.grid_2d_graph(5, 5).to_directed()
        assert_true(nx.is_isomorphic(G, gg))

        G = nx.navigable_small_world_graph(5, p=1, q=0, dim=3)
        gg = nx.grid_graph([5, 5, 5]).to_directed()
        assert_true(nx.is_isomorphic(G, gg))

        G = nx.navigable_small_world_graph(5, p=1, q=0, dim=1)
        gg = nx.grid_graph([5]).to_directed()
        assert_true(nx.is_isomorphic(G, gg)) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:14,代碼來源:test_geometric.py

示例12: test_node_input

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_node_input(self):
        G = nx.grid_graph([range(7, 9), range(3, 6)])
        assert_equal(len(G), 2 * 3)
        assert_true(nx.is_isomorphic(G, nx.grid_graph([2, 3]))) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:6,代碼來源:test_lattice.py

示例13: test_navigable_small_world

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import grid_graph [as 別名]
def test_navigable_small_world(self):
        G = nx.navigable_small_world_graph(5, p=1, q=0)
        gg = nx.grid_2d_graph(5, 5).to_directed()
        assert_true(nx.is_isomorphic(G, gg))

        G = nx.navigable_small_world_graph(5, p=1, q=0, dim=3)
        gg = nx.grid_graph([5, 5, 5]).to_directed()
        assert_true(nx.is_isomorphic(G, gg))

        G = nx.navigable_small_world_graph(5, p=1, q=0, dim=1)
        gg = nx.grid_graph([5]).to_directed()
        assert_true(nx.is_isomorphic(G, gg)) 
開發者ID:aws-samples,項目名稱:aws-kube-codesuite,代碼行數:14,代碼來源:test_geometric.py


注:本文中的networkx.grid_graph方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。