def ques4_plot(): """ Plot an example with two curves with legends """ ERGraph = uERAlgo(1239,0.004) UPAGraph = UPAalgo(1239,3) computer_nw = alg_application2_provided.load_graph(alg_application2_provided.NETWORK_URL) xvals = range(0,1240) yvals1 = module2.compute_resilience(ERGraph,alg_application2_provided.targeted_order(ERGraph)) yvals2 = module2.compute_resilience(UPAGraph,alg_application2_provided.targeted_order(UPAGraph)) yvals3 = module2.compute_resilience(computer_nw,alg_application2_provided.targeted_order(computer_nw)) #yvals1 = module2.compute_resilience(ERGraph,fast_targeted_order(ERGraph)) #yvals2 = module2.compute_resilience(UPAGraph,fast_targeted_order(UPAGraph)) #yvals3 = module2.compute_resilience(computer_nw,fast_targeted_order(computer_nw)) plt.xlabel("Number of Nodes Removed") plt.ylabel("Size of Largest Connected Component") plt.title("Size of Largest Connected Component vs Nodes Removed (using Targeted Order)") plt.plot(xvals, yvals1, '-g', label='ERGraph n = 1239,p = 0.004') plt.plot(xvals, yvals2, '-r', label='UPAGraph n = 1239, m = 3') plt.plot(xvals, yvals3, '-b', label='computer network') plt.legend(loc='upper right') plt.show() #ques4_plot()
def question1(network, er, upa, order_func, order_label, filename): N = len(network) order = order_func(network) network_res = module2.compute_resilience(network, order) er_res = module2.compute_resilience(er, order) upa_res = module2.compute_resilience(upa, order) xs = range(N + 1) plt.plot(xs, network_res, '-r', label='Network graph') plt.plot(xs, er_res, '-b', label='ER-generated (p = 0.00171)') plt.plot(xs, upa_res, '-g', label='UPA-generated (m = 2)') plt.title('Graph resilience (%s)' % order_label) plt.xlabel('Number of nodes removed') plt.ylabel('Size of the largest connected component') plt.legend(loc='upper right') plt.tight_layout() plt.savefig(filename) print('Saved plot to %s' % filename)
def legend_example(): """ Plot an example with two curves with legends """ ERGraph = uERAlgo(1239,0.004) UPAGraph = UPAalgo(1239,3) computer_nw = alg_application2_provided.load_graph(alg_application2_provided.NETWORK_URL) print countedges(ERGraph) print countedges(UPAGraph) print countedges(computer_nw) #deg_dict = compute_degrees(computer_nw) #total_deg = (sum(x for x in deg_dict.values()))/1239 #print total_deg xvals = range(0,1240) yvals1 = module2.compute_resilience(ERGraph,random_order(ERGraph)) yvals2 = module2.compute_resilience(UPAGraph,random_order(UPAGraph)) yvals3 = module2.compute_resilience(computer_nw,random_order(computer_nw)) #yvals1 = module2.compute_resilience(ERGraph,alg_application2_provided.targeted_order(ERGraph)) #yvals2 = module2.compute_resilience(UPAGraph,alg_application2_provided.targeted_order(UPAGraph)) #yvals3 = module2.compute_resilience(computer_nw,alg_application2_provided.targeted_order(computer_nw)) #yvals1 = module2.compute_resilience(ERGraph,fast_targeted_order(ERGraph)) #yvals2 = module2.compute_resilience(UPAGraph,fast_targeted_order(UPAGraph)) #yvals3 = module2.compute_resilience(computer_nw,fast_targeted_order(computer_nw)) print len(yvals1) print len(yvals2) print len(yvals3) plt.xlabel("Number of Nodes Removed") plt.ylabel("Size of Largest Connected Component") plt.title("Size of Largest Connected Component vs Nodes Removed") plt.plot(xvals, yvals1, '-g', label='ERGraph n = 1239,p = 0.004') plt.plot(xvals, yvals2, '-r', label='UPAGraph n = 1239, m = 3') plt.plot(xvals, yvals3, '-b', label='computer network') plt.legend(loc='upper right') plt.show()