# Load the network-graph
print "==========> Loading the network-graph"
network_graph = nagen.load_graph(nagen.NETWORK_URL)
# Generate the ER-graph
print
print "==========> Generating the ER-graph"
er_graph = nagen.make_graph_ER(1239, 0.0040)
# Generate the UPA-graph
print
print "==========> Generating the UPA-graph"
upa_graph = nagen.make_graph_UPA(1239, 3)

# Generate the attack orders for the three networks using fast_targeted_order
print
print "==========> Generating attack schedules"
network_attack = nagen.targeted_order(network_graph)
er_attack = nagen.targeted_order(er_graph)
upa_attack = nagen.targeted_order(upa_graph)

# Attack the computer-network
print
print "==========> Attacking the computer-network"
network_resilience = ca.compute_resilience(network_graph, network_attack)
# Attack the ER-network
print
print "==========> Attacking the ER-network"
er_resilience = ca.compute_resilience(er_graph, er_attack)
# Attack the UPA-network
print
print "==========> Attacking the UPA-network"
upa_resilience = ca.compute_resilience(upa_graph, upa_attack)
num_nodes = [0]
time_targeted_order = [0.0]
time_fast_targeted_order = [0.0]

# Generate all the point for the plot
for nodes in range(10, 1000, 10):
    # Fill in the nodes
    num_nodes.append(nodes)
    # Generate the graph to be used
    print "=====> Generating graph with", nodes, "nodes."
    UPA_graph = nagen.make_graph_UPA(nodes, 5)
    # Measure the time for targeted_order
    print
    print "=====> Run targeted_order for", nodes, "nodes."
    start_time = time.time()
    attack_list = nagen.targeted_order(UPA_graph)
    end_time = time.time()
    time_targeted_order.append(end_time - start_time)
    # Measure the time for fast_targeted_order
    print
    print "=====> Run fast_targeted_order for", nodes, "nodes."
    start_time = time.time()
    attack_list = nagen.fast_targeted_order(UPA_graph)
    end_time = time.time()
    time_fast_targeted_order.append(end_time - start_time)
    print
    
# Create plot of the result
plt.plot(num_nodes, time_targeted_order, '-b', label='Time targeted_order')
plt.plot(num_nodes, time_fast_targeted_order, '-r', label='Time fast_targeted_order')
plt.legend(loc='upper left')