def DPA(num_nodes, m):
    """
	DPA function return a DPA graph with num_nodes
	given num_nodes, and m : the number of existing nodes to which 
	a new node is connected in each iteration
	"""
    # make a m nodes completed graph
    m_node_comp_graph = make_complete_graph(m)
    current_graph = m_node_comp_graph
    dpatrial = DPATrial(m)
    for node in range(m, num_nodes):
        # sum of the in-degrees of existing nodes
        # choose randomly m nodes from V-current graph and
        # add them to V', where the probability of choosing node j
        # is (indeg(j)+1)/(totindeg+|V|)
        # totindeg = 0.0
        # in_degrees = compute_in_degrees(current_graph)
        # for node in in_degrees:
        # 	totindeg += in_degrees[node]
        # probability = (in_degrees[idx]+1.0)/(totindeg+len(current_graph))

        # using DPATrial class to encapsulate
        # optimized trials for DPA algorithm
        new_neighbours = dpatrial.run_trial(m)

        # new node i is added to set V
        # connect the new node to the randomly nodes
        current_graph.update({node: new_neighbours})
    return current_graph
Ejemplo n.º 2
0
def dpa_digraph_gen(target_node, step_node):
    dpa_graph = DPATrial(step_node)
    directed_graph = make_complete_graph(step_node)
    for i in range(step_node, target_node):
        directed_graph[i] = dpa_graph.run_trial(i)

    return directed_graph
Ejemplo n.º 3
0
def dpa_digraph_gen(target_node, step_node):
    '''
    generate digraph use DPA Algorithm

    Parameters
    ----------
    target_node : int
    step_node : int

    Returns
    -------
    graph : dict
    '''
    DPA_GRAPH = DPATrial(step_node)
    directed_graph = make_complete_graph(step_node)
    for i in range(step_node, target_node):
        directed_graph[i] = DPA_GRAPH.run_trial(i)
    return directed_graph