Beispiel #1
0
def test_second_split(graph, initial_partition):
    vertexes, q_partition = decorate_nx_graph(graph, initial_partition)
    xblock = q_partition[0].xblock

    qblock_splitter = q_partition[0]
    # qblock_splitter may be modified by split, therefore we need to keep a
    # copy
    splitter_vertexes = [vertex for vertex in qblock_splitter.vertexes]

    block_counterimage = build_block_counterimage(qblock_splitter)
    new_qblocks, _, _ = split(block_counterimage)
    q_partition.extend(new_qblocks)

    second_splitter_vertexes = list(
        filter(lambda vertex: vertex not in splitter_vertexes, vertexes))
    # E^{-1}(B) - E^{-1}(S-B)
    second_splitter_counterimage = build_exclusive_B_counterimage(
        splitter_vertexes)

    new_qblocks, _, _ = split(second_splitter_counterimage)
    q_partition.extend(new_qblocks)

    # after split the partition should be stable with respect to the block
    # chosen for the split
    for qblock in xblock.qblocks:
        assert check_vertexes_stability([vertex for vertex in qblock.vertexes],
                                        second_splitter_vertexes)
Beispiel #2
0
def test_second_splitter_counterimage(graph, initial_partition):
    vertexes, q_partition = decorate_nx_graph(graph, initial_partition)
    xblock = q_partition[0].xblock

    qblock_splitter = q_partition[0]

    # qblock_splitter may be modified by split, therefore we need to keep a
    # copy
    splitter_vertexes = [vertex for vertex in qblock_splitter.vertexes]

    block_counterimage = build_block_counterimage(qblock_splitter)
    split(block_counterimage)

    # compute S - B
    second_splitter_s_minus_b_vertexes = list(
        filter(lambda vertex: vertex not in splitter_vertexes, vertexes))

    # use the pta function to compute E^{-1}(B) - E^{-1}(S-B)
    second_splitter_counterimage = build_exclusive_B_counterimage(
        splitter_vertexes)

    for vertex in second_splitter_counterimage:
        assert vertex in block_counterimage and not any(
            map(
                lambda edge: edge in second_splitter_s_minus_b_vertexes,
                vertex.image,
            ))
Beispiel #3
0
def test_split(graph, initial_partition):
    vertexes, q_partition = decorate_nx_graph(graph, initial_partition)
    xblock = q_partition[0].xblock

    qblock_splitter = q_partition[0]
    # qblock_splitter may be modified by split, therefore we need to keep a
    # copy
    splitter_vertexes = [vertex for vertex in qblock_splitter.vertexes]

    block_counterimage = build_block_counterimage(qblock_splitter)
    split(block_counterimage)

    # after split the partition should be stable with respect to the block
    # chosen for the split
    for qblock in xblock.qblocks:
        assert check_vertexes_stability([vertex for vertex in qblock.vertexes],
                                        splitter_vertexes)

    # test if the size of the qblocks after the split is equal to the number of
    # vertexes
    for qblock in xblock.qblocks:
        assert qblock.size == len(qblock.vertexes)

    # check if the qblock a vertex belongs to corresponds to the value
    # vertex.qblock for each of its vertexes
    for qblock in xblock.qblocks:
        for vertex in qblock.vertexes:
            assert vertex.qblock == qblock
Beispiel #4
0
def test_vertex_taken_from_right_list(graph, initial_partition):
    vertexes, q_partition = decorate_nx_graph(graph, initial_partition)

    block_counterimage = build_block_counterimage(q_partition[0])

    for vertex in block_counterimage:
        qblock = vertex.qblock
        # this shouldn't raise an exception
        qblock.remove_vertex(vertex)
        assert True
Beispiel #5
0
def test_increase_n_of_xblocks_after_refinement(graph, initial_partition):
    vertexes_dllistobejct, q_partition = decorate_nx_graph(
        graph, initial_partition)

    xblock = q_partition[0].xblock

    xblocks = [xblock]
    compound_xblocks = [xblock]

    qblock_splitter = q_partition[0]
    block_counterimage = build_block_counterimage(qblock_splitter)
    refine(xblocks=xblocks, compound_xblocks=compound_xblocks)

    assert len(xblocks) == 2
Beispiel #6
0
def test_build_block_counterimage(graph, initial_partition):
    vertexes, q_partition = decorate_nx_graph(graph, initial_partition)
    for qblock in q_partition:

        def extract_vertex_label(llistobject):
            return llistobject.label

        block_counterimage = set(
            [vertex.label for vertex in build_block_counterimage(qblock)])

        right_block_counterimage = set()
        for edge in graph.edges:
            if edge[1] in list(
                    map(lambda vertex: vertex.label, qblock.vertexes)):
                right_block_counterimage.add(edge[0])

        assert right_block_counterimage == block_counterimage
Beispiel #7
0
def ranked_split(current_partition: List[_QBlock], B_qblock: _QBlock,
                 max_rank: int) -> List[Tuple[_Vertex]]:
    """Split the given partition using the block `B_qblock` as *splitter*, then
    use Ranked *Paige-Tarjan*'s algorithm on the resulting partition.

    :param current_partition: The current partition as a list of
        :class:`bispy.utilities.graph_entities._QBlock`.
    :param B_qblock: The block to be used as *splitter*.
    :param max_rank: The maximum rank which may be found in the graph.
    :returns: The output of Ranked *Paige-Tarjan*'s algorithm as a list of
        tuples of vertexes.
    """

    # initialize x_partition and q_partition
    x_partition = [
        # this also overwrites any information about parent xblocks for qblock
        _XBlock().append_qblock(qblock) for qblock in current_partition
    ]
    q_partition = current_partition

    #  perform Split(B,Q)
    B_counterimage = build_block_counterimage(B_qblock)
    new_qblocks, new_compound_xblocks, chaned_qblocks = split(B_counterimage)

    # reset aux_count
    for vx in B_counterimage:
        vx.aux_count = None

    q_partition.extend(new_qblocks)

    if max_rank == float("-inf"):
        max_rank = -1

    # note that only new compound xblock are compound xblocks
    compound_xblocks = RankedCompoundXBlocksContainer(new_compound_xblocks,
                                                      max_rank)

    return pta(x_partition, q_partition, compound_xblocks)
Beispiel #8
0
def test_build_block_counterimage_aux_count(graph, initial_partition):
    vertexes, q_partition = decorate_nx_graph(graph, initial_partition)

    for chosen_index in range(len(initial_partition)):
        qblock = q_partition[chosen_index]

        block_counterimage = build_block_counterimage(qblock)

        right_count = [0 for vertex in block_counterimage]
        for edge in graph.edges:
            if edge[1] in list(
                    map(lambda vertex: vertex.label, qblock.vertexes)):
                # update the count for edge[0]
                for idx in range(len(block_counterimage)):
                    if block_counterimage[idx].label == edge[0]:
                        right_count[idx] += 1

        assert right_count == [
            vertex.aux_count.value for vertex in block_counterimage
        ]

        for vertex in block_counterimage:
            vertex.aux_count = None