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 normalize_distribution(digraph): """ Normalizes the digraph return: dictionary with degrees normalized """ distribution = P1.in_degree_distribution(digraph) sum_nodes = len(digraph) normalized = dict.fromkeys(distribution) for degree in distribution: normalized[degree] = distribution[degree] / float(sum_nodes) return normalized
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 test_get_salary(self): self.assertEqual(20, Project_1.get_salary(8, 2, 4))