def testDelete():
    N = 100
    M = 5
    r = 0.5
    delete_amount = r * N
    remaining_nodes = N - delete_amount

    ER = create.ER_graph(N, 0.1, seed)
    SF = create.SF_graph(N, M, seed)

    ER_list = get.most_connected_nodes(ER)[1:5]
    ER_deleted = delete.connected_nodes(ER, ER_list)
    ER_nodes = len(ER)
    ER_remaining_nodes = len(ER_deleted)
    assert ER_nodes - 4 == ER_remaining_nodes, "Connected nodes has not been correctly implemented"

    SF_list = get.most_connected_nodes(SF)[1:5]
    SF_deleted = delete.connected_nodes(SF, SF_list)
    SF_nodes = len(SF)
    SF_remaining_nodes = len(SF_deleted)
    assert SF_nodes - 4 == SF_remaining_nodes, "Connected nodes has not been correctly implemented"

    ER = create.ER_graph(N, 0.1, seed)
    SF = create.SF_graph(N, seed)

    ER_random_delete = delete.random_nodes(ER, r)
    assert remaining_nodes == len(
        ER_random_delete.nodes
    ), "Random nodes are not being correctly deleted for ER graph"
    SF_random_delete = delete.random_nodes(SF, r)
    assert remaining_nodes == len(
        SF_random_delete.nodes
    ), "Random nodes are not being correctly deleted for SF graph"
Exemplo n.º 2
0
def generate_attack_small_s(G, remove_range):
    connected_nodes_list = get.most_connected_nodes(G)
    S = []

    for f in remove_range:
        modified_graph = delete.connected_nodes(G, f, connected_nodes_list)
        avg_isolated_cluster = get.isolated_clusters_len(modified_graph)
        S.append(avg_isolated_cluster)

    return S
def generate_attack(G, remove_range):
    connected_nodes_list = get.most_connected_nodes(G)
    diameters = []

    for f in remove_range:
        modified_graph = delete.connected_nodes(G, f, connected_nodes_list)
        recalculated_diameter = get.diameter(modified_graph)
        diameters.append(recalculated_diameter)

    return diameters
Exemplo n.º 4
0
def generate_attack(G, num_nodes, range):
    diameters = []

    for f in range:
        G_connected_nodes = get.most_connected_nodes(G)
        G_modified = delete.connected_nodes(G, f, G_connected_nodes)
        diameter = max_subgraph_diameter(G_modified)
        diameters.append(diameter)

    return diameters
Exemplo n.º 5
0
def generate_attack_big_S(G, remove_range, system_size):
    connected_nodes_list = get.most_connected_nodes(G)
    S = []

    for f in remove_range:
        modified_graph = delete.connected_nodes(G, f, connected_nodes_list)
        size_of_lg_cluster = get.largest_cluster_len(modified_graph)
        fraction_of_system = size_of_lg_cluster / system_size
        S.append(fraction_of_system)

    return S