def partial_duplication_graph(N, n, p, q, seed=None):
    if p < 0 or p > 1 or q < 0 or q > 1:
        msg = "partial duplication graph must have 0 <= p, q <= 1."
        raise NetworkXError(msg)
    if n > N:
        raise NetworkXError("partial duplication graph must have n <= N.")
    if seed is not None:
        random.seed(seed)

    G = nx.complete_graph(n)
    G.name = 'partial_duplication_graph({}, {}, {}, {})'.format(N, n, p, q)
    for new_node in range(n, N):
        # Add a new vertex, v, to the graph.
        G.add_node(new_node)

        # Pick a random vertex, u, already in the graph.
        src_node = random.randint(0, new_node)

        # Join v and u with probability q.
        if random.random() < q:
            G.add_edge(new_node, src_node)

        # For each neighbor of u...
        for neighbor_node in list(nx.all_neighbors(G, src_node)):
            # Add the neighbor to v with probability p.
            if random.random() < p:
                G.add_edge(new_node, neighbor_node)
    return G
Query service requests
dataset/ETHPy150Open networkx/networkx/networkx/generators/duplication.py/partial_duplication_graph--crossover with--dataset/ETHPy150Open miamidade/georeport-server/v2.py/search