Esempio n. 1
0
def test_ranked_split():
    g = nx.DiGraph()
    g.add_nodes_from(range(5))
    g.add_edges_from([(0, 1), (0, 2), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)])

    vertexes, _ = decorate_nx_graph(g)

    integer_partition = paige_tarjan(g)
    q_partition = integer_to_partition(integer_partition, vertexes)

    # now we modify the graph
    add_edge(vertexes[3], vertexes[0])

    # find [v]
    modified_destination_block = None
    for block in q_partition:
        for vertex in block.vertexes:
            if vertex.label == 0:
                modified_destination_block = block
                break

    ranked_split(q_partition, modified_destination_block, 2)

    final_integer_partition = partition_to_integer(q_partition)
    assert final_integer_partition == set(
        [frozenset([0]), frozenset([1, 2]), frozenset([3]), frozenset([4])]
    )
Esempio n. 2
0
def test_incremental_update_rscp_correctness(goal_graph, initial_partition):
    initial_graph = nx.DiGraph()
    initial_graph.add_nodes_from(goal_graph.nodes)

    partition = saha_partition(initial_graph, initial_partition)

    edges = []
    for edge in goal_graph.edges:
        edges.append(edge)

        g = nx.DiGraph()
        g.add_nodes_from(goal_graph.nodes)
        g.add_edges_from(edges)

        # compute its rscp
        rscp = set(
            map(
                frozenset,
                paige_tarjan(g, initial_partition, is_integer_graph=True),
            ))

        # compute the rscp incrementally
        rscp2 = partition.add_edge(edge)

        assert to_set(rscp2) == rscp
Esempio n. 3
0
def test_resets_aux_count():
    g = nx.DiGraph()
    g.add_nodes_from(range(5))
    g.add_edges_from([(0, 1), (0, 2), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)])

    vertexes, _ = decorate_nx_graph(g)

    integer_partition = paige_tarjan(g)
    q_partition = integer_to_partition(integer_partition, vertexes)

    # now we modify the graph
    add_edge(vertexes[3], vertexes[0])

    # find [v]
    modified_destination_block = None
    for block in q_partition:
        for vertex in block.vertexes:
            if vertex.label == 0:
                modified_destination_block = block
                break

    ranked_split(q_partition, modified_destination_block, 2)

    for vx in vertexes:
        assert not hasattr(vx, "aux_count") or vx.aux_count is None
Esempio n. 4
0
def test_reverse_incremental_update_rscp_correctness(
    goal_graph, initial_partition
):
    initial_graph = nx.DiGraph()
    initial_graph.add_nodes_from(goal_graph.nodes)
    vertexes, qblocks = decorate_nx_graph(initial_graph, initial_partition)

    edges = []
    full_edges = list(goal_graph.edges)
    full_edges.reverse()

    for edge in full_edges:
        edges.append(edge)

        g = nx.DiGraph()
        g.add_nodes_from(goal_graph.nodes)
        g.add_edges_from(edges)

        # compute its rscp
        rscp = paige_tarjan(g, initial_partition, is_integer_graph=True)
        rscp = ints_to_set(rscp)

        # compute the rscp incrementally
        qblocks = saha(qblocks, vertexes, edge)
        qblocks_as_int = [
            tuple(vx.label for vx in block.vertexes) for block in qblocks
        ]
        qblocks_as_int = ints_to_set(qblocks_as_int)

        assert qblocks_as_int == rscp
Esempio n. 5
0
def test_add_edges():
    graph = nx.balanced_tree(2, 3, create_using=nx.DiGraph)
    partition = saha_partition(graph)

    edges = [(1, 0), (8, 1)]

    new_graph = nx.balanced_tree(2, 3, create_using=nx.DiGraph)
    new_graph.add_nodes_from(range(len(graph.nodes)))
    new_graph.add_edges_from(graph.edges)
    new_graph.add_edges_from(edges)

    assert to_set(paige_tarjan(new_graph)) == set(
        map(frozenset, partition.add_edges(edges)))
Esempio n. 6
0
def test_balanced_tree_initial_partition():
    graph = nx.balanced_tree(2, 3, create_using=nx.DiGraph)
    initial_partition = [
        (0, 1, 2),
        (3, 4),
        (5, 6),
        (7, 8, 9, 10),
        (11, 12, 13),
        (14, ),
    ]
    assert to_set(
        dovier_piazza_policriti(
            graph, initial_partition=initial_partition)) == to_set(
                paige_tarjan(graph, initial_partition=initial_partition))
Esempio n. 7
0
def test_no_compound_xblocks():
    G = nx.DiGraph()
    G.add_edges_from([[0, 1], [1, 2], [2, 1]])
    assert len(paige_tarjan(G)) == 1
Esempio n. 8
0
def test_pt_no_integer_nodes():
    graph = nx.DiGraph()
    graph.add_nodes_from(["a", 0, 1, 2, 3, frozenset("x")])
    graph.add_edges_from([("a", 0), (0, 1), (1, 2), (2, 3)])
    s = paige_tarjan(graph, [["a", 0, 1, 2], [3, frozenset("x")]])
    assert set(s) == set([("a", ), (0, ), (1, ), (2, ), (3, frozenset("x"))])
Esempio n. 9
0
def test_pt_no_initial_partition():
    graph = test_cases.build_full_graphs(10)
    paige_tarjan(graph)
    assert True
Esempio n. 10
0
def test_pt_correctness(graph, initial_partition, expected_q_partition):
    s = paige_tarjan(graph, initial_partition)
    assert set(frozenset(tp) for tp in s) == set(
        frozenset(tp) for tp in expected_q_partition)
Esempio n. 11
0
def test_dpp_correctness2(graph):
    assert to_set(dovier_piazza_policriti(graph)) == to_set(
        paige_tarjan(graph))
Esempio n. 12
0
def test_dpp_rscp_correctness(graph, initial_partition, expected_q_partition):
    assert to_set(dovier_piazza_policriti(graph, initial_partition)) == to_set(
        paige_tarjan(graph, initial_partition))