Python networkx.grid_graph() Examples
The following are 14
code examples of networkx.grid_graph().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: test_embedding_chimera.py From dwave-system with Apache License 2.0 | 6 votes |
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])
Example #2
Source File: test_embedding_chimera.py From dwave-system with Apache License 2.0 | 6 votes |
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))
Example #3
Source File: test_embedding_chimera.py From dwave-system with Apache License 2.0 | 6 votes |
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))
Example #4
Source File: test_lattice.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
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())
Example #5
Source File: test_lattice.py From aws-kube-codesuite with Apache License 2.0 | 6 votes |
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())
Example #6
Source File: minigc.py From dgl with Apache License 2.0 | 5 votes |
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)
Example #7
Source File: synthetic_structsim.py From gnn-model-explainer with Apache License 2.0 | 5 votes |
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
Example #8
Source File: test_chimera_layout.py From dwave_networkx with Apache License 2.0 | 5 votes |
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())
Example #9
Source File: test_pegasus_layout.py From dwave_networkx with Apache License 2.0 | 5 votes |
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)
Example #10
Source File: test_geometric.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
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))
Example #11
Source File: test_geometric.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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))
Example #12
Source File: test_lattice.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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])))
Example #13
Source File: test_geometric.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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))
Example #14
Source File: test_lattice.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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])))