def UPA_graph(num_nodes, exist_nodes): """ num_nodes (int) - number of nodes to add exist_nodes (int) - number of existing nodes to connect to return: digraph (dict) """ ugraph = prj1.make_complete_graph(exist_nodes) for new_node in xrange(exist_nodes, num_nodes): total_in = prj1.compute_in_degrees(ugraph) total_indegrees = 0 for node in total_in: total_indegrees += total_in[node] trial = UPATrial(total_indegrees) to_connect = trial.run_trial(exist_nodes) ugraph[new_node] = to_connect return ugraph
def UPA_graph(num_nodes, exist_nodes): """ num_nodes (int) - number of nodes to add exist_nodes (int) - number of existing nodes to connect to return: digraph (dict) """ ugraph = prj1.make_complete_graph(exist_nodes) for new_node in xrange(exist_nodes, num_nodes): total_in = prj1.compute_in_degrees(ugraph) total_indegrees = 0 for node in total_in: total_indegrees += total_in[node] trial = UPATrial(total_indegrees) to_connect = trial.run_trial(exist_nodes) ugraph[new_node] = to_connect return ugraph
def DPA_algo(num_nodes, exist_nodes): """ num_nodes (int) - number of nodes to add exist_nodes (int) - number of existing nodes to connect to return: digraph (dict) """ #initialize variables for direction graph digraph = prj1.make_complete_graph(exist_nodes) #create DPA graph for new_node in xrange(exist_nodes, num_nodes): total_in = prj1.compute_in_degrees(digraph) total_indegrees = 0 for node in total_in: total_indegrees += total_in[node] trial = DPATrial(total_indegrees) to_connect = trial.run_trial(exist_nodes) digraph[new_node] = to_connect #return direction DPA graph return digraph
def edge_tester(ugraph): total_ins = prj1.compute_in_degrees(ugraph) sum = 0 for node in total_ins: sum += total_ins[node] print sum / 2
def edge_tester(ugraph): total_ins = prj1.compute_in_degrees(ugraph) sum = 0 for node in total_ins: sum += total_ins[node] print sum / 2