示例#1
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
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
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
示例#4
0
def DPAalgo(n,m,add):
    m_graph = make_complete_graph(m)
    random_connect = DPA(m)
    for i in xrange(m,n):
        m_graph[i]=random_connect.run_trial(add)
    distribution = in_degree_distribution(m_graph)
    distribution.pop(0)
    return distribution
示例#5
0
def make_random_graph_DPA(m,n):    
    random_graph = make_complete_graph(m)
    initial_graph = DPATrial(m)
    
    for i in range(n-m):
        new_node_neighbors = initial_graph.run_trial(m)
        random_graph[initial_graph._num_nodes-1] = new_node_neighbors
        
    return random_graph
示例#6
0
def DPAalgo(n,m):
    distribution = {}
    if(1 <= m < n):
        m_graph = make_complete_graph(m)
        #random_connect = DPA(m)
        for i in xrange(m,n):
            in_deg_dict = compute_in_degrees(m_graph)
            total_in = sum(x for x in in_deg_dict.values())
            trial = DPA(total_in)
            m_graph[i] = trial.run_trial(m)
        distribution = in_degree_distribution(m_graph)
        distribution.pop(0)
    return distribution
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
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