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


Python networkx.random_regular_graph方法代码示例

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


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

示例1: generate_eulerian_circuit_data

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_regular_graph [as 别名]
def generate_eulerian_circuit_data(options):

    while True:
        num_nodes = options["num_entities"]
        g = nx.random_regular_graph(2, num_nodes)

        try:
            path = list(nxalg.eulerian_circuit(g))
        except:
            continue

        # print path

        break

    for edge in g.edges():
        print "%s connected-to %s" % (edge[0], edge[1])
        print "%s connected-to %s" % (edge[1], edge[0])

    first_edge = path[0]

    node_list = [str(edge[0]) for edge in path]
    print "eval eulerian-circuit %s %s\t%s" % (first_edge[0], first_edge[1],
                                               ",".join(node_list))


##################### noisy data ####################### 
开发者ID:calebmah,项目名称:ggnn.pytorch,代码行数:29,代码来源:generate_data.py

示例2: generate_noisy_eulerian_circuit_data

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_regular_graph [as 别名]
def generate_noisy_eulerian_circuit_data(options):
    """
    This is a noisy version of the eularian circuit problem.
    """
    while True:
        num_nodes = options["num_entities"]
        g = nx.random_regular_graph(2, num_nodes)

        try:
            path = list(nxalg.eulerian_circuit(g))
        except:
            continue
        break

    edges = g.edges()

    # generate another misleading cycle
    num_confusing = options["num_confusing"]
    if num_confusing > 0:
        g_confusing = nx.random_regular_graph(2, num_confusing)

        for e in g_confusing.edges():
            edges.append((e[0] + num_nodes, e[1] + num_nodes))

    random.shuffle(edges)

    # randomize index
    idx = _generate_random_node_index(num_nodes + num_confusing)
    new_edges = _relabel_nodes_in_edges(edges, idx)
    new_path = _relabel_nodes_in_edges(path, idx)

    for edge in new_edges:
        print "%s connected-to %s" % (edge[0], edge[1])
        print "%s connected-to %s" % (edge[1], edge[0])

    first_edge = new_path[0]

    node_list = [str(edge[0]) for edge in new_path]
    print "eval eulerian-circuit %s %s\t%s" % (first_edge[0], first_edge[1],
                                               ",".join(node_list)) 
开发者ID:calebmah,项目名称:ggnn.pytorch,代码行数:42,代码来源:generate_data.py

示例3: test_graph6

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_regular_graph [as 别名]
def test_graph6():
    graph0 = nx.random_regular_graph(4, 10)
    g0 = to_graph6(graph0)
    graph1 = from_graph6(g0)
    g1 = to_graph6(graph1)

    assert g0 == g1 
开发者ID:rigetti,项目名称:quantumflow,代码行数:9,代码来源:test_utils.py

示例4: random_k_regular_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_regular_graph [as 别名]
def random_k_regular_graph(degree: int,
                           nodes: List[Union[int, QubitPlaceholder]],
                           seed: int = None,
                           weighted: bool = False,
                           biases: bool = False) -> nx.Graph:
    """
    Produces a random graph with specified number of nodes, each having degree k.

    Parameters
    ----------
    degree:
        Desired degree for the nodes
    nodes:
        The node set of the graph. Can be anything that works as a qubit for
        PauliSums.
    seed:
        A seed for the random number generator
    weighted:
        Whether the edge weights should be uniform or different. If false, all weights are set to 1.
        If true, the weight is set to a random number drawn from the uniform distribution in the interval 0 to 1.
        If true, the weight is set to a random number drawn from the uniform
        distribution in the interval 0 to 1.
    biases:
        Whether or not the graph nodes should be assigned a weight.
        If true, the weight is set to a random number drawn from the uniform
        distribution in the interval 0 to 1.

    Returns
    -------
    nx.Graph:
        A graph with the properties as specified.

    """
    np.random.seed(seed=seed)

    # create a random regular graph on the nodes
    G = nx.random_regular_graph(degree, len(nodes), seed)
    nx.relabel_nodes(G, {i: n for i, n in enumerate(nodes)})

    for edge in G.edges():
        if not weighted:
            G[edge[0]][edge[1]]['weight'] = 1
        else:
            G[edge[0]][edge[1]]['weight'] = np.random.rand()

    if biases:
        for node in G.nodes():
            G.node[node]['weight'] = np.random.rand()

    return G 
开发者ID:entropicalabs,项目名称:entropica_qaoa,代码行数:52,代码来源:utilities.py

示例5: _cli

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_regular_graph [as 别名]
def _cli():

    parser = argparse.ArgumentParser(
        description=__description__)

    parser.add_argument('--version', action='version', version=__version__)

    parser.add_argument('-d', '--degree', type=float, action='store',
                        help='Degree')

    parser.add_argument('--family', type=str, action='store', default='er',
                        help='Graph family')

    parser.add_argument('N', type=int, action='store', help='Nodes')

    parser.add_argument('S', type=int, action='store', help='Samples')

    parser.add_argument('fout', action='store',
                        metavar='OUT_FILE', help='Write graphs to file')

    opts = vars(parser.parse_args())
    N = opts.pop('N')
    S = opts.pop('S')
    fout = opts.pop('fout')

    degree = opts.pop('degree')
    family = opts.pop('family')
    assert family in {'er', 'reg'}

    if family == 'reg':
        assert degree is not None
        degree = int(degree)

    with open(fout, 'w') as file:
        for _ in range(S):
            if family == 'er':
                graph = nx.gnp_random_graph(N, 0.5)
            elif family == 'reg':
                graph = nx.random_regular_graph(int(degree), N)
            else:
                assert False
            file.write(to_graph6(graph))
            file.write('\n') 
开发者ID:rigetti,项目名称:quantumflow,代码行数:45,代码来源:graph_generate.py


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