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
def test2(): print(bfs_visited.compute_resilience(test_graphs_mod2.GRAPH0, [1,2]))