Ejemplo n.º 1
0
def test_backmap():
    t = Tiling(
        obstructions=(
            GriddedPerm(Perm((0, )), ((0, 0), )),
            GriddedPerm(Perm((0, 1)), ((0, 1), (0, 1))),
            GriddedPerm(Perm((0, 1)), ((0, 2), (0, 2))),
            GriddedPerm(Perm((0, 1)), ((0, 2), (1, 2))),
            GriddedPerm(Perm((0, 1)), ((1, 0), (1, 2))),
            GriddedPerm(Perm((0, 1)), ((1, 1), (1, 2))),
            GriddedPerm(Perm((0, 1)), ((1, 2), (1, 2))),
            GriddedPerm(Perm((1, 0)), ((0, 2), (1, 2))),
            GriddedPerm(Perm((1, 0)), ((1, 1), (1, 1))),
            GriddedPerm(Perm((1, 0)), ((1, 2), (1, 2))),
            GriddedPerm(Perm((0, 2, 1)), ((0, 1), (0, 2), (0, 2))),
            GriddedPerm(Perm((0, 2, 1)), ((1, 0), (1, 0), (1, 0))),
            GriddedPerm(Perm((0, 2, 1)), ((1, 0), (1, 1), (1, 0))),
            GriddedPerm(Perm((1, 2, 0)), ((0, 1), (0, 2), (1, 1))),
            GriddedPerm(Perm((1, 2, 0)), ((0, 1), (1, 2), (1, 1))),
            GriddedPerm(Perm((1, 2, 0)), ((1, 0), (1, 0), (1, 0))),
            GriddedPerm(Perm((2, 0, 1)), ((0, 2), (0, 1), (0, 2))),
            GriddedPerm(Perm((2, 0, 1)), ((1, 1), (1, 0), (1, 0))),
            GriddedPerm(Perm((2, 0, 1)), ((1, 2), (1, 0), (1, 0))),
            GriddedPerm(Perm((2, 1, 0)), ((0, 1), (1, 1), (1, 0))),
            GriddedPerm(Perm((2, 1, 0)), ((0, 2), (1, 1), (1, 0))),
            GriddedPerm(Perm((2, 1, 0)), ((1, 2), (1, 1), (1, 0))),
            GriddedPerm(Perm((2, 3, 0, 1)), ((0, 1), (0, 2), (1, 0), (1, 0))),
        ),
        requirements=((GriddedPerm(Perm((0, )), ((1, 2), )), ), ),
        assumptions=(),
    )
    cellmap1 = {
        (0, 1): (0, 1),
        (1, 0): (2, 0),
        (1, 1): (2, 1),
        (1, 2): (1, 2),
    }
    cellmap2 = {
        (0, 1): (0, 1),
        (1, 2): (1, 3),
        (2, 0): (2, 0),
        (2, 1): (3, 2),
    }
    final_cell_map = {
        (0, 1): (0, 1),
        (1, 0): (2, 0),
        (1, 1): (3, 2),
        (1, 2): (1, 3),
    }
    rcs1 = _RowColSeparationSingleApplication(t)
    t1 = rcs1.separated_tiling()
    assert rcs1.get_cell_map() == cellmap1
    rcs2 = _RowColSeparationSingleApplication(t1)
    t2 = rcs2.separated_tiling()
    assert rcs2.get_cell_map() == cellmap2
    rcs = RowColSeparation(t)
    assert rcs.separated_tiling() == t2
    assert RowColSeparation(t).get_cell_map() == final_cell_map
Ejemplo n.º 2
0
def test_all_separation():
    t = Tiling(obstructions=[
        GriddedPerm(Perm((0, 1)), ((0, 0), ) * 2),
        GriddedPerm(Perm((0, 1)), ((1, 0), ) * 2),
        GriddedPerm(Perm((0, 1)), ((0, 0), (1, 0))),
        GriddedPerm(Perm((1, 0)), ((0, 0), (1, 0))),
    ])
    assert len(
        list(
            _RowColSeparationSingleApplication(t).all_separated_tiling())) == 2
    assert (len(
        list(
            _RowColSeparationSingleApplication(t).all_separated_tiling(
                only_max=False))) == 2)
Ejemplo n.º 3
0
def test_all_order():
    t = Tiling(obstructions=[GriddedPerm(Perm((0, 1)), ((0, 0), (1, 0)))])
    rcs = _RowColSeparationSingleApplication(t)
    assert list(rcs._all_order(rcs.row_ineq_graph())) == [[{(1, 0)}, {(0, 0)}]]
    assert list(rcs._all_order(rcs.col_ineq_graph())) == [[{(0, 0)}, {(1, 0)}]]
    t = Tiling(obstructions=[
        GriddedPerm(Perm((0, 1)), ((0, 0), (1, 0))),
        GriddedPerm(Perm((1, 0)), ((0, 0), (1, 0))),
    ])
    rcs = _RowColSeparationSingleApplication(t)
    assert sorted(rcs._all_order(rcs.row_ineq_graph())) == [
        [{(1, 0)}, {(0, 0)}],
        [{(0, 0)}, {(1, 0)}],
    ]
    assert list(rcs._all_order(rcs.col_ineq_graph())) == [[{(0, 0)}, {(1, 0)}]]
Ejemplo n.º 4
0
def test_complete_inequalities_matrices(separable_tiling2):
    rcs = _RowColSeparationSingleApplication(separable_tiling2)
    row_m, col_m = rcs._complete_ineq_matrices()
    # Row basic matrix
    ob_ineq = [
        ((1, 0), (0, 0)),
        ((2, 0), (0, 0)),
        ((3, 0), (0, 0)),
        ((1, 1), (0, 1)),
        ((2, 1), (0, 1)),
        ((2, 0), (1, 0)),
        ((2, 1), (1, 1)),
        ((3, 0), (2, 0)),
    ]
    for c1, c2 in product(separable_tiling2.active_cells, repeat=2):
        if c1[1] < c2[1] or (c1, c2) in ob_ineq:
            print(1, c1, c2)
            assert_matrix_entry_is(rcs, row_m, c1, c2, 1)
        else:
            print(0, c1, c2)
            assert_matrix_entry_is(rcs, row_m, c1, c2, 0)
    assert rcs._ineq_matrices == (row_m, col_m)
    # Column basic matrix
    ob_ineq = [((0, 1), (0, 0))]
    for c1, c2 in product(separable_tiling2.active_cells, repeat=2):
        if c1[0] < c2[0] or (c1, c2) in ob_ineq:
            assert_matrix_entry_is(rcs, col_m, c1, c2, 1)
        else:
            assert_matrix_entry_is(rcs, col_m, c1, c2, 0)
Ejemplo n.º 5
0
def test_backmap3():
    t = Tiling(
        obstructions=(
            GriddedPerm(Perm((0, 1)), ((0, 0), (0, 0))),
            GriddedPerm(Perm((0, 1)), ((0, 0), (0, 1))),
            GriddedPerm(Perm((0, 1)), ((0, 0), (0, 2))),
            GriddedPerm(Perm((0, 1)), ((0, 0), (1, 1))),
            GriddedPerm(Perm((0, 1)), ((0, 0), (2, 0))),
            GriddedPerm(Perm((0, 1)), ((0, 0), (2, 2))),
            GriddedPerm(Perm((0, 1)), ((0, 1), (0, 2))),
            GriddedPerm(Perm((0, 1)), ((0, 1), (1, 1))),
            GriddedPerm(Perm((0, 1)), ((0, 2), (0, 2))),
            GriddedPerm(Perm((0, 1)), ((1, 1), (1, 1))),
            GriddedPerm(Perm((0, 1)), ((1, 1), (2, 1))),
            GriddedPerm(Perm((0, 1)), ((2, 0), (2, 0))),
            GriddedPerm(Perm((1, 0)), ((0, 0), (2, 0))),
            GriddedPerm(Perm((1, 0)), ((0, 1), (0, 0))),
            GriddedPerm(Perm((1, 0)), ((0, 1), (2, 1))),
            GriddedPerm(Perm((1, 0)), ((0, 2), (0, 0))),
            GriddedPerm(Perm((1, 0)), ((0, 2), (0, 1))),
            GriddedPerm(Perm((1, 0)), ((1, 1), (2, 1))),
            GriddedPerm(Perm((1, 0)), ((2, 1), (2, 0))),
            GriddedPerm(Perm((1, 0)), ((2, 1), (2, 1))),
            GriddedPerm(Perm((1, 0)), ((2, 2), (2, 1))),
            GriddedPerm(Perm((0, 1, 2)), ((0, 1), (0, 1), (2, 1))),
            GriddedPerm(Perm((0, 1, 2)), ((0, 1), (2, 1), (2, 2))),
            GriddedPerm(Perm((0, 2, 1)), ((0, 1), (0, 1), (0, 1))),
            GriddedPerm(Perm((0, 2, 1)), ((0, 1), (2, 2), (2, 2))),
            GriddedPerm(Perm((0, 2, 1)), ((2, 1), (2, 2), (2, 2))),
            GriddedPerm(Perm((0, 2, 1)), ((2, 2), (2, 2), (2, 2))),
            GriddedPerm(Perm((1, 0, 2)), ((2, 2), (2, 2), (2, 2))),
            GriddedPerm(Perm((1, 2, 0)), ((0, 2), (2, 2), (2, 2))),
            GriddedPerm(Perm((1, 2, 0)), ((2, 2), (2, 2), (2, 2))),
            GriddedPerm(Perm((2, 0, 1)), ((0, 1), (0, 1), (0, 1))),
            GriddedPerm(Perm((2, 0, 1)), ((2, 2), (2, 0), (2, 2))),
            GriddedPerm(Perm((2, 0, 1)), ((2, 2), (2, 2), (2, 2))),
            GriddedPerm(Perm((2, 1, 0)), ((0, 2), (2, 2), (2, 0))),
            GriddedPerm(Perm((2, 1, 0)), ((0, 2), (2, 2), (2, 2))),
            GriddedPerm(Perm((2, 1, 0)), ((2, 2), (2, 2), (2, 0))),
            GriddedPerm(Perm((2, 1, 0)), ((2, 2), (2, 2), (2, 2))),
        ),
        requirements=((GriddedPerm(Perm((0, )), ((2, 1), )), ), ),
    )
    cellmap1 = {
        (0, 0): (2, 0),
        (0, 1): (0, 2),
        (0, 2): (1, 4),
        (2, 0): (3, 1),
        (2, 1): (3, 3),
        (2, 2): (3, 4),
    }
    print(t)
    rcs1 = _RowColSeparationSingleApplication(t)
    t1 = rcs1.separated_tiling()
    print(t1)
    assert rcs1.get_cell_map() == cellmap1
    rcs = RowColSeparation(t)
    assert rcs.separated_tiling() == t1
    assert rcs.get_cell_map() == cellmap1
Ejemplo n.º 6
0
def test_cell_order(separable_tiling1):
    rcs = _RowColSeparationSingleApplication(separable_tiling1)
    ob = GriddedPerm(Perm((0, 1)), ((0, 0), (0, 1)))
    assert rcs._col_cell_order(ob) == ((0, 1), (0, 0))
    ob = GriddedPerm(Perm((1, 0)), ((0, 1), (0, 0)))
    assert rcs._col_cell_order(ob) == ((0, 0), (0, 1))
    ob = GriddedPerm(Perm((0, 1)), ((0, 0), (1, 0)))
    assert rcs._row_cell_order(ob) == ((1, 0), (0, 0))
    ob = GriddedPerm(Perm((1, 0)), ((0, 0), (1, 0)))
    assert rcs._row_cell_order(ob) == ((0, 0), (1, 0))
Ejemplo n.º 7
0
def test_map_gridded_perm(separable_tiling1):
    rcs = _RowColSeparationSingleApplication(separable_tiling1)
    ob = GriddedPerm(Perm((0, 1, 2)), ((0, 0), (1, 0), (1, 0)))
    cell_map = {(0, 0): (0, 0), (1, 0): (1, 1)}
    assert rcs._map_gridded_perm(cell_map,
                                 ob) == GriddedPerm(Perm((0, 1, 2)),
                                                    ((0, 0), (1, 1), (1, 1)))
    ob = GriddedPerm(Perm((0, 1, 2)), ((0, 0), (1, 0), (1, 0)))
    assert rcs._map_gridded_perm(cell_map,
                                 ob) == GriddedPerm(Perm((0, 1, 2)),
                                                    ((0, 0), (1, 1), (1, 1)))
Ejemplo n.º 8
0
def test_maximal_order():
    t = Tiling(obstructions=[
        GriddedPerm(Perm((0, 1)), ((0, 0), (1, 0))),
        GriddedPerm(Perm((1, 0)), ((0, 0), (1, 0))),
    ])
    rcs = _RowColSeparationSingleApplication(t)
    possible_order = [
        [{(1, 0)}, {(0, 0)}],
        [{(0, 0)}, {(1, 0)}],
    ]
    assert sorted(rcs._maximal_order(rcs.row_ineq_graph())) in possible_order
    assert rcs.max_row_order in possible_order
    assert list(rcs._maximal_order(rcs.col_ineq_graph())) == [{(0, 0)},
                                                              {(1, 0)}]
    assert rcs.max_col_order == [{(0, 0)}, {(1, 0)}]
Ejemplo n.º 9
0
def test_basic_matrix(separable_tiling2):
    rcs = _RowColSeparationSingleApplication(separable_tiling2)
    # Row basic matrix
    m = rcs._basic_matrix(True)
    for c1, c2 in product(separable_tiling2.active_cells, repeat=2):
        if c1[1] < c2[1]:
            assert_matrix_entry_is(rcs, m, c1, c2, 1)
        else:
            assert_matrix_entry_is(rcs, m, c1, c2, 0)
    # Column basic matrix
    m = rcs._basic_matrix(False)
    for c1, c2 in product(separable_tiling2.active_cells, repeat=2):
        if c1[0] < c2[0]:
            assert_matrix_entry_is(rcs, m, c1, c2, 1)
        else:
            assert_matrix_entry_is(rcs, m, c1, c2, 0)
Ejemplo n.º 10
0
def test_separates_tiling():
    t = Tiling(
        obstructions=[
            GriddedPerm(Perm((0, 1)), ((0, 0), (1, 0))),
            GriddedPerm(Perm((2, 0, 1)), ((0, 0), (1, 0), (1, 0))),
            GriddedPerm(Perm((2, 0, 1)), ((0, 0), (0, 0), (0, 0))),
            GriddedPerm(Perm((2, 0, 1)), ((1, 0), (1, 0), (1, 0))),
        ],
        requirements=[[GriddedPerm(Perm((0, )), ((1, 0), ))]],
    )
    print(t)
    rcs = _RowColSeparationSingleApplication(t)
    row_order = [{(1, 0)}, {(0, 0)}]
    col_order = [{(0, 0)}, {(1, 0)}]
    sep_t = rcs._separates_tiling(row_order, col_order)
    print(sep_t)
    assert sep_t == Tiling(
        obstructions=[
            GriddedPerm(Perm((2, 0, 1)), ((0, 1), (1, 0), (1, 0))),
            GriddedPerm(Perm((2, 0, 1)), ((0, 1), (0, 1), (0, 1))),
            GriddedPerm(Perm((2, 0, 1)), ((1, 0), (1, 0), (1, 0))),
        ],
        requirements=[[GriddedPerm(Perm((0, )), ((1, 0), ))]],
    )
Ejemplo n.º 11
0
def test_col_ineq_graph(separable_tiling2):
    rcs = _RowColSeparationSingleApplication(separable_tiling2)
    assert rcs.col_ineq_graph()._matrix == rcs._complete_ineq_matrices()[1]
Ejemplo n.º 12
0
def test_cell_at_idx(separable_tiling2):
    rcs = _RowColSeparationSingleApplication(separable_tiling2)
    for i in range(len(separable_tiling2.active_cells)):
        assert i == rcs.cell_idx(rcs.cell_at_idx(i))
Ejemplo n.º 13
0
def test_cell_idx(separable_tiling2):
    rcs = _RowColSeparationSingleApplication(separable_tiling2)
    for c in separable_tiling2.active_cells:
        assert c == rcs.cell_at_idx(rcs.cell_idx(c))
Ejemplo n.º 14
0
def test_init(separable_tiling2):
    rcs = _RowColSeparationSingleApplication(separable_tiling2)
    assert rcs._tiling == separable_tiling2
    assert len(rcs._active_cells) == 7
    assert (3, 1) not in rcs._active_cells