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


Python networkx.grid_2d_graph方法代码示例

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


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

示例1: test_generate_binary_constraints

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def test_generate_binary_constraints():
    row_count, col_count = 3, 3
    grid_graph = nx.grid_2d_graph(row_count, col_count, periodic=True)
    domain = Domain("d", "d", [0, 1])
    variables = generate_binary_variables(grid_graph, domain)
    bin_range= 1.6

    constraints = generate_binary_constraints(grid_graph, variables, bin_range, True)
    assert len(constraints) == len(list(grid_graph.edges))
    for constraint in constraints.values():
        assert type(constraint) == NAryMatrixRelation
        check_binary_constraint(constraint, bin_range)

    constraints = generate_binary_constraints(grid_graph, variables, bin_range, False)
    assert len(constraints) == len(list(grid_graph.edges))
    for constraint in constraints.values():
        assert type(constraint) == NAryFunctionRelation
        check_binary_constraint(constraint, bin_range) 
开发者ID:Orange-OpenSource,项目名称:pyDcop,代码行数:20,代码来源:test_generate_ising.py

示例2: test_dijkstra_predecessor

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def test_dijkstra_predecessor(self):
        G = nx.path_graph(4)
        assert_equal(nx.dijkstra_predecessor_and_distance(G, 0),
                     ({0: [], 1: [0], 2: [1], 3: [2]}, {0: 0, 1: 1, 2: 2, 3: 3}))
        G = nx.grid_2d_graph(2, 2)
        pred, dist = nx.dijkstra_predecessor_and_distance(G, (0, 0))
        assert_equal(sorted(pred.items()),
                     [((0, 0), []), ((0, 1), [(0, 0)]),
                      ((1, 0), [(0, 0)]), ((1, 1), [(0, 1), (1, 0)])])
        assert_equal(sorted(dist.items()),
                     [((0, 0), 0), ((0, 1), 1), ((1, 0), 1), ((1, 1), 2)])

        XG = nx.DiGraph()
        XG.add_weighted_edges_from([('s', 'u', 10), ('s', 'x', 5),
                                    ('u', 'v', 1), ('u', 'x', 2),
                                    ('v', 'y', 1), ('x', 'u', 3),
                                    ('x', 'v', 5), ('x', 'y', 2),
                                    ('y', 's', 7), ('y', 'v', 6)])
        (P, D) = nx.dijkstra_predecessor_and_distance(XG, 's')
        assert_equal(P['v'], ['u'])
        assert_equal(D['v'], 9)
        (P, D) = nx.dijkstra_predecessor_and_distance(XG, 's', cutoff=8)
        assert_false('v' in D) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:25,代码来源:test_weighted.py

示例3: test_generate_binary_variables

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def test_generate_binary_variables():
    grid_graph = nx.grid_2d_graph(4, 5, periodic=True)
    domain = Domain("d", "d", [0, 1])

    variables = generate_binary_variables(grid_graph, domain)

    assert len(variables) == 4 * 5
    for name, variable in variables.items():
        assert variable.domain == domain
        assert name == variable.name 
开发者ID:Orange-OpenSource,项目名称:pyDcop,代码行数:12,代码来源:test_generate_ising.py

示例4: generate_grid_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def generate_grid_graph(variables_count):
    side = math.sqrt(variables_count)
    if int(side) != side:
        raise ValueError(
            f"The value {variables_count} provided for"
            "the option --variables_count is not a valid square"
            "grid size"
        )
    side = int(side)
    graph = nx.grid_2d_graph(side, side)
    return graph 
开发者ID:Orange-OpenSource,项目名称:pyDcop,代码行数:13,代码来源:graphcoloring.py

示例5: test_encode_decode_adj

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def test_encode_decode_adj():
######## code test ###########
    G = nx.ladder_graph(5)
    G = nx.grid_2d_graph(20,20)
    G = nx.ladder_graph(200)
    G = nx.karate_club_graph()
    G = nx.connected_caveman_graph(2,3)
    print(G.number_of_nodes())
    
    adj = np.asarray(nx.to_numpy_matrix(G))
    G = nx.from_numpy_matrix(adj)
    #
    start_idx = np.random.randint(adj.shape[0])
    x_idx = np.array(bfs_seq(G, start_idx))
    adj = adj[np.ix_(x_idx, x_idx)]
    
    print('adj\n',adj)
    adj_output = encode_adj(adj,max_prev_node=5)
    print('adj_output\n',adj_output)
    adj_recover = decode_adj(adj_output,max_prev_node=5)
    print('adj_recover\n',adj_recover)
    print('error\n',np.amin(adj_recover-adj),np.amax(adj_recover-adj))
    
    
    adj_output = encode_adj_flexible(adj)
    for i in range(len(adj_output)):
        print(len(adj_output[i]))
    adj_recover = decode_adj_flexible(adj_output)
    print(adj_recover)
    print(np.amin(adj_recover-adj),np.amax(adj_recover-adj)) 
开发者ID:JiaxuanYou,项目名称:graph-generation,代码行数:32,代码来源:data.py

示例6: test_grid

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def test_grid(self):
        G = nx.grid_2d_graph(6, 7)

        tw, order = self.heuristic(G)
        self.assertGreaterEqual(tw, 6)
        self.check_order(G, order) 
开发者ID:dwavesystems,项目名称:dwave_networkx,代码行数:8,代码来源:test_elimination_ordering.py

示例7: test_spanning_tree_count

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def test_spanning_tree_count():
    grp = nx.grid_2d_graph(3, 3)
    count = spanning_tree_count(grp)
    assert count == 192 
开发者ID:rigetti,项目名称:quantumflow,代码行数:6,代码来源:test_utils.py

示例8: create_grid_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def create_grid_graph(self):
        # This function creates the grid graph of size (w+1)x(h+1) as described in the paper
        self.grid_graph = networkx.grid_2d_graph(
            self.width + 1, self.height + 1) 
开发者ID:vvanirudh,项目名称:Pixel-Art,代码行数:6,代码来源:algorithm.py

示例9: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def setUp(self):
        self.Gi=nx.grid_2d_graph(5,5)
        self.Gs=nx.Graph()
        self.Gs.add_path('abcdef')
        self.bigG=nx.grid_2d_graph(25,25) #bigger than 500 nodes for sparse 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:7,代码来源:test_layout.py

示例10: test_cartesian_product_classic

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def test_cartesian_product_classic():
    # test some classic product graphs
    P2 = nx.path_graph(2)
    P3 = nx.path_graph(3)
    # cube = 2-path X 2-path
    G = cartesian_product(P2, P2)
    G = cartesian_product(P2, G)
    assert_true(nx.is_isomorphic(G, nx.cubical_graph()))

    # 3x3 grid
    G = cartesian_product(P3, P3)
    assert_true(nx.is_isomorphic(G, nx.grid_2d_graph(3, 3))) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:14,代码来源:test_product.py

示例11: _setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def _setUp(self):
    cnlti = nx.convert_node_labels_to_integers
    self.grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
    self.cycle = nx.cycle_graph(7)
    self.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
    self.XG = nx.DiGraph()
    self.XG.add_weighted_edges_from([('s', 'u', 10), ('s', 'x', 5),
                                     ('u', 'v', 1), ('u', 'x', 2),
                                     ('v', 'y', 1), ('x', 'u', 3),
                                     ('x', 'v', 5), ('x', 'y', 2),
                                     ('y', 's', 7), ('y', 'v', 6)])
    self.MXG = nx.MultiDiGraph(self.XG)
    self.MXG.add_edge('s', 'u', weight=15)
    self.XG2 = nx.DiGraph()
    self.XG2.add_weighted_edges_from([[1, 4, 1], [4, 5, 1],
                                      [5, 6, 1], [6, 3, 1],
                                      [1, 3, 50], [1, 2, 100], [2, 3, 100]])

    self.XG3 = nx.Graph()
    self.XG3.add_weighted_edges_from([[0, 1, 2], [1, 2, 12],
                                      [2, 3, 1], [3, 4, 5],
                                      [4, 5, 1], [5, 0, 10]])

    self.XG4 = nx.Graph()
    self.XG4.add_weighted_edges_from([[0, 1, 2], [1, 2, 2],
                                      [2, 3, 1], [3, 4, 1],
                                      [4, 5, 1], [5, 6, 1],
                                      [6, 7, 1], [7, 0, 1]])
    self.MXG4 = nx.MultiGraph(self.XG4)
    self.MXG4.add_edge(0, 1, weight=3)
    self.G = nx.DiGraph()  # no weights
    self.G.add_edges_from([('s', 'u'), ('s', 'x'),
                           ('u', 'v'), ('u', 'x'),
                           ('v', 'y'), ('x', 'u'),
                           ('x', 'v'), ('x', 'y'),
                           ('y', 's'), ('y', 'v')]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:38,代码来源:test_weighted.py

示例12: test_others

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def test_others(self):
        (P, D) = nx.bellman_ford(self.XG, 's')
        assert_equal(P['v'], 'u')
        assert_equal(D['v'], 9)
        (P, D) = nx.goldberg_radzik(self.XG, 's')
        assert_equal(P['v'], 'u')
        assert_equal(D['v'], 9)

        G = nx.path_graph(4)
        assert_equal(nx.bellman_ford(G, 0),
                     ({0: None, 1: 0, 2: 1, 3: 2}, {0: 0, 1: 1, 2: 2, 3: 3}))
        assert_equal(nx.goldberg_radzik(G, 0),
                     ({0: None, 1: 0, 2: 1, 3: 2}, {0: 0, 1: 1, 2: 2, 3: 3}))
        assert_equal(nx.bellman_ford(G, 3),
                     ({0: 1, 1: 2, 2: 3, 3: None}, {0: 3, 1: 2, 2: 1, 3: 0}))
        assert_equal(nx.goldberg_radzik(G, 3),
                     ({0: 1, 1: 2, 2: 3, 3: None}, {0: 3, 1: 2, 2: 1, 3: 0}))

        G = nx.grid_2d_graph(2, 2)
        pred, dist = nx.bellman_ford(G, (0, 0))
        assert_equal(sorted(pred.items()),
                     [((0, 0), None), ((0, 1), (0, 0)),
                      ((1, 0), (0, 0)), ((1, 1), (0, 1))])
        assert_equal(sorted(dist.items()),
                     [((0, 0), 0), ((0, 1), 1), ((1, 0), 1), ((1, 1), 2)])
        pred, dist = nx.goldberg_radzik(G, (0, 0))
        assert_equal(sorted(pred.items()),
                     [((0, 0), None), ((0, 1), (0, 0)),
                      ((1, 0), (0, 0)), ((1, 1), (0, 1))])
        assert_equal(sorted(dist.items()),
                     [((0, 0), 0), ((0, 1), 1), ((1, 0), 1), ((1, 1), 2)]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:33,代码来源:test_weighted.py

示例13: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def setUp(self):
        from networkx import convert_node_labels_to_integers as cnlti
        self.grid=cnlti(nx.grid_2d_graph(4,4),first_label=1,ordering="sorted")
        self.cycle=nx.cycle_graph(7)
        self.directed_cycle=nx.cycle_graph(7,create_using=nx.DiGraph()) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:7,代码来源:test_unweighted.py

示例14: test_predecessor

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def test_predecessor(self):
        G=nx.path_graph(4)
        assert_equal(nx.predecessor(G,0),{0: [], 1: [0], 2: [1], 3: [2]})
        assert_equal(nx.predecessor(G,0,3),[2])
        G=nx.grid_2d_graph(2,2)
        assert_equal(sorted(nx.predecessor(G,(0,0)).items()),
                     [((0, 0), []), ((0, 1), [(0, 0)]),
                      ((1, 0), [(0, 0)]), ((1, 1), [(0, 1), (1, 0)])]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:10,代码来源:test_unweighted.py

示例15: test_grid_2d_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import grid_2d_graph [as 别名]
def test_grid_2d_graph():
    # All minimum node cuts of a 2d grid
    # are the four pairs of nodes that are
    # neighbors of the four corner nodes.
    G = nx.grid_2d_graph(5, 5)
    solution = [
        set([(0, 1), (1, 0)]),
        set([(3, 0), (4, 1)]),
        set([(3, 4), (4, 3)]),
        set([(0, 3), (1, 4)]),
    ]
    for cut in nx.all_node_cuts(G):
        assert_true(cut in solution) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:15,代码来源:test_kcutsets.py


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