def question3(): """ calculates and plots running time of fast_targeted_order versus targeted_order for a series of increasingly larger UPA graphs """ t_o_times = [] f_t_o_times = [] graph_sizes = [] for num_nodes in range(10, 1000, 10): graph_sizes.append(num_nodes) curr_graph = app2_create_graphs.upa(num_nodes, 5) t_o_start = time.time() app2_provided.targeted_order(curr_graph) t_o_times.append(time.time() - t_o_start) f_t_o_start = time.time() fast_order.fast_targeted_order(curr_graph) f_t_o_times.append(time.time() - f_t_o_start) pyplot.plot(graph_sizes, t_o_times, color='red', linestyle='-', marker=None, label='targeted_order') pyplot.plot(graph_sizes, f_t_o_times, color='blue', linestyle='-', marker=None, label='fast_targeted_order') pyplot.title('Comparison of algorithm running times: Desktop Python') pyplot.xlabel('number of nodes in upa graph') pyplot.ylabel('running time in seconds') pyplot.grid(True) pyplot.legend(loc='upper left') pyplot.show()
def question1(): """ create 3 graphs - subject each to the same random attack order plot the resulting largest cc for each """ network_graph = app2_provided.load_graph(app2_provided.NETWORK_URL) attack_order = random_order(network_graph) network_resil = bfs_visited.compute_resilience(network_graph, attack_order) er_graph = app2_create_graphs.undirected_er(1239, 0.002) attack_order = random_order(er_graph) while count_edges(er_graph) < 2900 or count_edges(er_graph) > 3190: er_graph = app2_create_graphs.undirected_er(1239, 0.002) er_resil = bfs_visited.compute_resilience(er_graph, attack_order) upa_graph = app2_create_graphs.upa(1239, 3) attack_order = random_order(upa_graph) upa_resil = bfs_visited.compute_resilience(upa_graph, attack_order) pyplot.plot(range(1240), network_resil, color='red', linestyle='-', marker=None, label='Network Graph') pyplot.plot(range(1240), er_resil, color='blue', linestyle='-', marker=None, label='ER Graph, p=0.002') pyplot.plot(range(1240), upa_resil, color='green', linestyle='-', marker=None, label='UPA Graph, m=3') pyplot.title('Question 1\nComparison of Random Attack Graph Degradation') pyplot.xlabel('Number of Nodes Removed') pyplot.ylabel('Largest Connected Component') pyplot.legend(loc='upper right') pyplot.grid(True) pyplot.show() return network_resil, er_resil, upa_resil