def UPAalgo(n,m): m_graph = make_complete_graph(m) random_connect = UPA(m) for i in xrange(m,n): if i not in m_graph.keys(): m_graph[i] = set() m_graph[i] = random_connect.run_trial(m) for item in m_graph[i]: m_graph[item].update([i]) #m_graph[i] = random_connect.run_trial(m) return m_graph
def make_random_graph_UPA(m,n): random_graph = make_complete_graph(m) for dummy in range(n-m): random_graph[dummy + m] = set() initial_graph = UPATrial(m) for dummy in range(n-m): new_node_neighbors = initial_graph.run_trial(m) random_graph[dummy + m] = new_node_neighbors for new_neighbor in new_node_neighbors: random_graph[new_neighbor].add(dummy + m) return random_graph
def upa_makegraph(num_nodes, iter_nodes): """ Generates graph by UPA algorithm where num_nodes is a total number of nodes and iter_nodes is a number of edges added on each iteration """ result = prj1.make_complete_graph(iter_nodes) upa = UPATrial(iter_nodes) if num_nodes <= iter_nodes: return result for step in range(iter_nodes, num_nodes): nodes_to_be_added = upa.run_trial(iter_nodes) result[step] = nodes_to_be_added for node in nodes_to_be_added: result[node].add(step) return result
def upa_undigraph_gen(node_num, step_node): ''' generate un-digraph use UPA Algorithm Parameters ---------- node_num : int step_node : int Returns ------- graph : dict ''' UPAGraph = UPATrial(step_node) graph = make_complete_graph(step_node) for i in range(step_node, node_num): neighbors = UPAGraph.run_trial(step_node) graph[i] = neighbors for nei in neighbors: graph[nei] = graph.get(nei, set()).union({i}) return graph