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_split_helper_block_right_xblock(graph, initial_partition):
    vertexes, q_partition = decorate_nx_graph(graph, initial_partition)
    new_blocks, _, _ = split(vertexes[3:7])

    for new_block in new_blocks:
        assert any(
            [qblock == new_block for qblock in new_block.xblock.qblocks])

    for old_block in q_partition:
        assert old_block.size == 0 or any(
            [qblock == old_block for qblock in old_block.xblock.qblocks])
Beispiel #5
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)