def question_4(): example_network = load_graph(NETWORK_URL) er_undirected = er_und.random_undirected_graph(1239, 0.002) upa_graph = upa.upa_generator(1239, 3) er_attack = fast_targeted_order(er_undirected) upa_attack = fast_targeted_order(upa_graph) network_attack = fast_targeted_order(example_network) er_resilience = bfs.compute_resilience(er_undirected, er_attack) upa_resilience = bfs.compute_resilience(upa_graph, upa_attack) network_resilience = bfs.compute_resilience(example_network, network_attack) # Create a new figure of size 8x6 points, using 100 dots per inch plt.figure(figsize=(8,6), dpi=80) # Create a new subplot from a grid of 1x1 plt.subplot(1,1,1) #parameters: row, column, location index plt.xlabel("Number of removed nodes") plt.ylabel("Size of the Largest Component") plt.title("The Resilience of Different Types of Networks - using Targeted Order") # Generate points X = [n for n in range(len(er_resilience))] # Plot cosine using blue color with a continuous line of width 1 (pixels) plt.plot(X, er_resilience, color="blue", linewidth=2.0, linestyle="-", label="ER Graph") # Plot sine using green color with a continuous line of width 1 (pixels) plt.plot(X, upa_resilience, color="green", linewidth=2.0, linestyle="-", label="UPA Graph") plt.plot(X, network_resilience, color="red", linewidth=2.0, linestyle="-", label="Example Network") # Add Legends plt.legend(loc='upper right', frameon=False) # Show result on screen plt.show()
def question_1(): # THE CORRECT probability factor p for er_undirected should be 0.002 # also, I SHOULD HAVE LISTED the values of p and m example_network = load_graph(NETWORK_URL) er_undirected = er_und.random_undirected_graph(1239, 0.002) upa = upa.upa_generator(1239, 3) er_attack = random_order(er_undirected) upa_attack = random_order(upa) network_attack = random_order(example_network) er_resilience = bfs.compute_resilience(er_undirected, er_attack) upa_resilience = bfs.compute_resilience(upa, upa_attack) network_resilience = bfs.compute_resilience(example_network, network_attack) # Create a new figure of size 8x6 points, using 100 dots per inch plt.figure(figsize=(10, 6), dpi=80) # Create a new subplot from a grid of 1x1 plt.subplot(1, 1, 1) #parameters: row, column, location index plt.xlabel("Number of removed nodes") plt.ylabel("Size of the Largest Component") plt.title("The Resilience of Different Types of Networks") # Generate points X = [n for n in range(len(er_resilience))] # Plot cosine using blue color with a continuous line of width 1 (pixels) plt.plot(X, er_resilience, color="blue", linewidth=2.0, linestyle="-", label="ER Graph") # Plot sine using green color with a continuous line of width 1 (pixels) plt.plot(X, upa_resilience, color="green", linewidth=2.0, linestyle="-", label="UPA Graph") plt.plot(X, network_resilience, color="red", linewidth=2.0, linestyle="-", label="Example Network") # Add Legends plt.legend(loc='upper right', frameon=False) # Show result on screen plt.show()
def question_2(): graph_list = [] # generate UPA graphs with n in range(10, 1000) and m = 5 for num_nodes in range(10, 1000, 10): graph_list.append(upa.upa_generator(num_nodes, 5)) num_nodes = [idx for idx in range(10, 1000, 10)] time_fast_target = [] time_normal_target = [] for each_graph in graph_list: start_time = time.time() fast_targeted_order(each_graph) elapsed_time = time.time() - start_time time_fast_target.append(elapsed_time) start_time = time.time() targeted_order(each_graph) elapsed_time = time.time() - start_time time_normal_target.append(elapsed_time) # Plot data # Create a new figure of size 8x6 points, using 100 dots per inch plt.figure(figsize=(8, 8), dpi=80) # Create a new subplot from a grid of 1x1 plt.subplot(1, 1, 1) #parameters: row, column, location index plt.xlabel("Number of Nodes") plt.ylabel("Time Elapsed") plt.title("Comparasion of Two Target-finder Methods (on Desktop)") # Plot cosine using blue color with a continuous line of width 1 (pixels) plt.plot(num_nodes, time_fast_target, color="blue", linewidth=2.0, linestyle="-", label="Fast Targeted Order") # Plot sine using green color with a continuous line of width 1 (pixels) plt.plot(num_nodes, time_normal_target, color="green", linewidth=2.0, linestyle="-", label="(Normal) Targeted Order") # Add Legends plt.legend(loc='upper left', frameon=False) # Show result on screen plt.show()
def question_2(): graph_list = [] # generate UPA graphs with n in range(10, 1000) and m = 5 for num_nodes in range(10, 1000, 10): graph_list.append(upa.upa_generator(num_nodes, 5)) num_nodes = [idx for idx in range(10, 1000, 10)] time_fast_target = [] time_normal_target = [] for each_graph in graph_list: start_time = time.time() fast_targeted_order(each_graph) elapsed_time = time.time() - start_time time_fast_target.append(elapsed_time) start_time = time.time() targeted_order(each_graph) elapsed_time = time.time() - start_time time_normal_target.append(elapsed_time) # Plot data # Create a new figure of size 8x6 points, using 100 dots per inch plt.figure(figsize=(8,8), dpi=80) # Create a new subplot from a grid of 1x1 plt.subplot(1,1,1) #parameters: row, column, location index plt.xlabel("Number of Nodes") plt.ylabel("Time Elapsed") plt.title("Comparasion of Two Target-finder Methods (on Desktop)") # Plot cosine using blue color with a continuous line of width 1 (pixels) plt.plot(num_nodes, time_fast_target, color="blue", linewidth=2.0, linestyle="-", label="Fast Targeted Order") # Plot sine using green color with a continuous line of width 1 (pixels) plt.plot(num_nodes, time_normal_target, color="green", linewidth=2.0, linestyle="-", label="(Normal) Targeted Order") # Add Legends plt.legend(loc='upper left', frameon=False) # Show result on screen plt.show()