def question4_plot():
    """
    Loads the three graphs in the problem, calculates a sequence of targeted
    attacks using fast_targeted_attack and calculates the resilience of each 
    graph based on this attack. Plots the results.
    """

    # Loading the provided computer network example
    example_graph = graph_provided.load_graph(NETWORK_URL)

    # Creating a random ER graph with 1239 nodes and p = .004
    er_graph = make_random_ugraph(1239, .004)

    # Creating an UPA graph, m=12
    upa_graph = mod_upa.create_UPA_graph(1239, 2)

    # Calculating attack sequences with the provided targeted_order
    #example_attack = graph_provided.targeted_order(example_graph)
    #er_attack = graph_provided.targeted_order(er_graph)
    #upa_attack = graph_provided.targeted_order(upa_graph)

    # Calculating attack sequences with fast_targeted_order
    example_attack = fast_targeted_order(example_graph)
    er_attack = fast_targeted_order(er_graph)
    upa_attack = fast_targeted_order(upa_graph)

    # Calculating resilience
    example_resilience = mod_resilience.compute_resilience(example_graph, 
                                                           example_attack)
    er_resilience = mod_resilience.compute_resilience(er_graph, 
                                                      er_attack)
    upa_resilience = mod_resilience.compute_resilience(upa_graph, 
                                                       upa_attack)

    # Plotting the outcome 
    xvals = range(1240)

    plt.plot(xvals, example_resilience, '-c', 
             label='computer network example (provided)')
    plt.plot(xvals, er_resilience, '-y', 
             label='generated ER graph (p = .004)')
    plt.plot(xvals, upa_resilience, '-m', 
             label='generated UPA graph (m = 2)')
    plt.legend(loc='upper right')
    plt.title('Graphs resilience to targeted attack')
    plt.xlabel('Nodes removed')
    plt.ylabel('Biggest connected element size')
    plt.show()
def question3_plot():
    """
    Calculates a series of targeted attacks using both functions (provided and
    the fast targeted implemented one), computes the running time of these 
    processes and plots the outcome
    """
    # Initializing the data series
    xvals = range(10 , 1000, 10)
    targeted_times = []
    fast_targeted_times = []
    
    for size in range(10, 1000, 10):
        upa_graph = mod_upa.create_UPA_graph(size, 5)
        
        # Calculating the running time of targeted_attack for this iteration
        start_clock = time.clock()
        graph_provided.targeted_order(upa_graph)
        end_clock = time.clock() - start_clock
        targeted_times.append(end_clock * 1000)
        
        # Calculating the running time of fast_targeted_attack for this iteration
        start_clock = time.clock()
        fast_targeted_order(upa_graph)
        end_clock = time.clock() - start_clock
        fast_targeted_times.append(end_clock * 1000)
        
    # Plotting the outcome 
    plt.plot(xvals, targeted_times, '-c', 
             label='targeted_order times (O(n**2))')
    plt.plot(xvals, fast_targeted_times, '-y', 
             label='fast_targeted_order times (O(n))')
    plt.legend(loc='upper left')
    plt.title('Processing times to calculate attacks (desktop Python)')
    plt.ylabel('Running time (milliseconds)')
    plt.xlabel('Graph size')
    plt.show()