def main(): m = 5 fast_times = [] targeted_times = [] x = range(10, 1000, 10) for n in x: graph = upa(n, m) start_time = timeit.default_timer() fast_targeted_order(graph) end_time = timeit.default_timer() - start_time fast_times.append(end_time) start_time = timeit.default_timer() targeted_order(graph) end_time = timeit.default_timer() - start_time targeted_times.append(end_time) print fast_times print targeted_times plt.xlabel('Number of Nodes') plt.ylabel('Running Time in seconds') plt.title('Fast Targeted vs Targeted Order functions runtime (Desktop Python)') plt.plot(x, fast_times, '-b', label='Fast Targeted') plt.plot(x, targeted_times, '-r', label='Targeted Order') plt.legend(loc='upper left') plt.grid(True) plt.savefig('targeted.png') plt.show()
def main(): net_graph = network_graph() net_size = sum([len(x) for x in net_graph.itervalues()]) print net_size/2 # net_attack = random_order(net_graph) net_resilience = np.array(calculate_resilience(net_graph)) print 'net: ', sum([len(x) for x in net_graph.itervalues()])/len(net_graph) e_graph = er_graph(1239, 0.0020) size = sum([len(x) for x in e_graph.itervalues()]) print size/2 print e_graph # e_attack = random_order(e_graph) e_resilience = np.array(calculate_resilience(e_graph)) print 'e: ', sum([len(x) for x in e_graph.itervalues()])/len(e_graph) upa_graph = upa(1239, 3) #print upa_graph upa_size = sum([len(x) for x in upa_graph.itervalues()]) print upa_size/2 upa_resilience = np.array(calculate_resilience(upa_graph)) print 'upa: ', sum([len(x) for x in upa_graph.itervalues()])/len(upa_graph) x = np.array(range(max(len(net_resilience), len(e_resilience), len(upa_resilience)))) plt.xlabel('Number of nodes removed') plt.ylabel('Size of the largest connected component') plt.title('Resilience of computer networks under attack') plt.plot(x, net_resilience, '-b', label='Network') plt.plot(x, e_resilience, '-r', label='ER | p = 0.0020') plt.plot(x, upa_resilience, '-y', label='UPA | m = 3') plt.legend(loc='upper right') plt.grid(True) plt.savefig('question4.png') plt.show()