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
Exemplo n.º 3
0
def dpa(n_nodes, m_nodes):
    '''
    Helper function to implement the DPA algorithm for Question 4
    '''
    graph = project1.make_complete_graph(m_nodes)
    dpa_alg = alg_dpa_trial.DPATrial(m_nodes)
    for node in range(m_nodes, n_nodes):
        graph[node] = dpa_alg.run_trial(m_nodes)
    return graph
def upa_graph(total_nodes, min_nodes):
    graph = project1.make_complete_graph(min_nodes)
    upa_trial = upa.UPATrial(min_nodes)

    for node in range(min_nodes, total_nodes):
        neighbors = upa_trial.run_trial(min_nodes)
        graph[node] = neighbors
        for neighbor in neighbors:
            graph[neighbor].add(node)

    #print ("# of edges in UPA Graph -> " + str(utility.count_num_of_edges(graph)))
    return graph
def upa(num_nodes, in_degree):
    """
    creates a random undirected graph with n nodes and average in-degree of m
    input: no_nodes (m) and in_degree(m) - both integers
    output: directed graph (dictionary, with edges as sets)
    """
    upa_graph = project1.make_complete_graph(in_degree)
    node_counter = upa_trial.UPATrial(in_degree)
    for new_node in range(in_degree, num_nodes):
        new_node_set = node_counter.run_trial(in_degree)
        upa_graph[new_node] = new_node_set
        for vertex in new_node_set:
            upa_graph[vertex].add(new_node)

    return upa_graph
Exemplo n.º 6
0
def upa_algorithm(lenght, number_of_nodes):
    '''
    Function for generating graph with some : param probability edges for every node
    :param lenght: (int) lenght of nodes in graph (int)
    :param probability: :float. Probability
    :return:
    '''
    graph = project1.make_complete_graph(number_of_nodes)
    upa_alg = alg_upa_trial.UPATrial(number_of_nodes)
    #print upa_alg._node_numbers
    for node in xrange(number_of_nodes, lenght):
        nodes_to_connect = upa_alg.run_trial(number_of_nodes)
        graph[node] = nodes_to_connect
        for gen_node in nodes_to_connect:
            graph[gen_node].add(node)
    #print "upa graph", graph
    return graph
def dpa(n, m):
    """
    Implementation of DPA algorithm

    Parameters
    ----------
    n: int
    final number of nodes

    m: int
    number of existing nodes

    Returns
    -------
    graph: dict
    a dictionary representing a final directed graph
    """
    graph = make_complete_graph(m)
    dpa_helper = DPATrial(m)
    # run m to n - 1 trials
    for new_node in range(m, n):
        graph[new_node] = dpa_helper.run_trial(m)
    return graph
Exemplo n.º 8
0
def algorithm_dpa(n, m):
    graph = project1.make_complete_graph(m)
    dpa = alg_dpa_trial.DPATrial(m)
    for i in range(m, n):
        graph[i] = dpa.run_trial(m)
    return graph
Exemplo n.º 9
0
def algorithm_dpa(n, m):
    graph = project1.make_complete_graph(m)
    dpa = alg_dpa_trial.DPATrial(m)
    for i in xrange(m, n):
        graph[i] = dpa.run_trial(m)
    return graph
Exemplo n.º 10
0
def generate_DPA(m, n):
    graph = make_complete_graph(m)
    dpatrail = DPATrial(m)
    for i in xrange(m, n):
        graph[i] = dpatrail.run_trial(m)
    return graph
Exemplo n.º 11
0
def generate_DPA(m, n):
    graph = make_complete_graph(m)
    dpatrail = DPATrial(m)
    for i in xrange(m, n):
        graph[i] = dpatrail.run_trial(m)
    return graph