Esempio n. 1
0
def test_132_genf():
    searcher = TileScope([Perm((0, 2, 1))], point_placements)
    spec = searcher.auto_search(smallest=True)
    spec = spec.expand_verified()
    av = Av([Perm((0, 2, 1))])
    for i in range(10):
        assert set(av.of_length(i)) == set(
            gp.patt for gp in spec.generate_objects_of_size(i))
        assert spec.random_sample_object_of_size(i).patt in av
    gf = spec.get_genf()
    gf = sympy.series(spec.get_genf(), n=15)
    x = sympy.Symbol("x")
    assert [gf.coeff(x, n) for n in range(13)] == [
        1,
        1,
        2,
        5,
        14,
        42,
        132,
        429,
        1430,
        4862,
        16796,
        58786,
        208012,
    ]
Esempio n. 2
0
def gps_indices_direction_owncol_ownrow_ignoreparent_includeempty(strategy):
    return [
        strategy(
            gps=gps,
            indices=indices,
            direction=direction,
            own_col=own_col,
            own_row=own_row,
            ignore_parent=ignore_parent,
            include_empty=include_empty,
        ) for (
            gps,
            indices,
        ), direction, own_col, own_row, ignore_parent, include_empty in
        product(
            (
                ((GriddedPerm(Perm((0, )), ((0, 0), )), ), (0, )),
                ((GriddedPerm.single_cell(Perm((0, 1, 2)), (2, 1)), ), (1, )),
                (
                    (
                        GriddedPerm(Perm((0, 1)), ((0, 1), (1, 1))),
                        GriddedPerm(Perm((1, 0)), ((2, 2), (3, 1))),
                    ),
                    (1, 0),
                ),
            ),
            (DIR_EAST, DIR_WEST, DIR_NORTH, DIR_SOUTH),
            (True, False),
            (True, False),
            (True, False),
            (True, False),
        )
    ]
Esempio n. 3
0
def test_splitting_gf():
    parent = Tiling(
        obstructions=(
            GriddedPerm.single_cell(Perm((0, 1)), (0, 1)),
            GriddedPerm.single_cell(Perm((0, 1)), (1, 0)),
        ),
        assumptions=(
            TrackingAssumption([
                GriddedPerm.point_perm((0, 1)),
                GriddedPerm.point_perm((1, 0))
            ]),
            TrackingAssumption([GriddedPerm.point_perm((1, 0))]),
        ),
    )
    child = Tiling(
        obstructions=(
            GriddedPerm.single_cell(Perm((0, 1)), (0, 1)),
            GriddedPerm.single_cell(Perm((0, 1)), (1, 0)),
        ),
        assumptions=(
            TrackingAssumption([GriddedPerm.point_perm((0, 1))]),
            TrackingAssumption([GriddedPerm.point_perm((1, 0))]),
        ),
    )
    strat = SplittingStrategy()
    rule = strat(parent)
    x, k0, k1 = var("x k_0 k_1")
    parent_func = Function("F_0")(x, k0, k1)
    child_func = Function("F_1")(x, k0, k1)
    expected_eq = Eq(parent_func, child_func.subs({k1: k0 * k1}))

    assert len(rule.children) == 1
    assert rule.children[0] == child
    assert rule.constructor.get_equation(parent_func,
                                         (child_func, )) == expected_eq
Esempio n. 4
0
    def _cell_insertion_custom(
        self, x: int, y: int, button: int, _modifiers: int
    ) -> None:
        """Add a custom obstruction or requirement to a single cell.

        Args:
            x (int): The x coordinate of the mouse click.
            y (int): The y coordinate of the mouse click.
            button (int): The mouse button clicked.
            _modifiers (int): If combinded with modifiers (e.g. ctrl). Unused.
        """
        tplot = self._current()
        if button == pyglet.window.mouse.LEFT:
            self._add_tiling(
                tplot.tiling.add_single_cell_requirement(
                    Perm.to_standard(self._custom_data),
                    tplot.get_cell(Point(x, y)),
                )
            )
        elif button == pyglet.window.mouse.RIGHT:
            self._add_tiling(
                tplot.tiling.add_single_cell_obstruction(
                    Perm.to_standard(self._custom_data),
                    tplot.get_cell(Point(x, y)),
                )
            )
Esempio n. 5
0
    def test_pack(self, strategy, enum_verified):
        assert strategy.pack(
            enum_verified[0]) == TileScopePack.point_placements(
            ).add_verification(BasicVerificationStrategy(), replace=True)
        assert strategy.pack(enum_verified[1]) in (
            TileScopePack.regular_insertion_encoding(2),
            TileScopePack.regular_insertion_encoding(3),
        )

        assert strategy.pack(
            enum_verified[2]) == TileScopePack.regular_insertion_encoding(3)

        assert strategy.pack(
            enum_verified[3]) == TileScopePack.regular_insertion_encoding(2)
        assert strategy.pack(
            enum_verified[4]) == TileScopePack.row_and_col_placements(
            ).fix_one_by_one([Perm((0, 1, 2)),
                              Perm((2, 3, 0, 1))])

        assert strategy.pack(
            enum_verified[5]) == TileScopePack.row_and_col_placements(
                row_only=True).make_fusion(tracked=True).fix_one_by_one(
                    [Perm((0, 1, 2))])
        with pytest.raises(InvalidOperationError):
            strategy.pack(enum_verified[6])
Esempio n. 6
0
def test_321_1324():
    searcher = TileScope("321_1324", reginsenc)
    spec = searcher.auto_search()
    assert isinstance(spec, CombinatorialSpecification)
    for i in range(20):
        gp = spec.random_sample_object_of_size(i)
        assert all(cell == (0, 0) for cell in gp.pos)
        assert gp.patt.avoids(Perm((2, 1, 0)), Perm((0, 2, 1, 3)))
    assert [spec.count_objects_of_size(i) for i in range(50)] == [
        1,
        1,
        2,
        5,
        13,
        32,
        72,
        148,
        281,
        499,
        838,
        1343,
        2069,
        3082,
        4460,
        6294,
        8689,
        11765,
        15658,
        20521,
        26525,
        33860,
        42736,
        53384,
        66057,
        81031,
        98606,
        119107,
        142885,
        170318,
        201812,
        237802,
        278753,
        325161,
        377554,
        436493,
        502573,
        576424,
        658712,
        750140,
        851449,
        963419,
        1086870,
        1222663,
        1371701,
        1534930,
        1713340,
        1907966,
        2119889,
        2350237,
    ]
Esempio n. 7
0
def not_fact_tiling():
    not_fact_tiling = Tiling(obstructions=[
        GriddedPerm(Perm((0, 1)), ((0, 0), (0, 0))),
        GriddedPerm(Perm((0, 1)), ((0, 0), (0, 1))),
        GriddedPerm(Perm((0, 1)), ((0, 1), (0, 1))),
    ])
    return not_fact_tiling
Esempio n. 8
0
 def obs_inf1(self, tiling1):
     obs_trans = ObstructionInferral(tiling1)
     obs_trans.potential_new_obs = MagicMock(return_value=[
         GriddedPerm(Perm((0, 1)), [(0, 0), (0, 0)]),
         GriddedPerm(Perm((1, 0)), [(0, 0), (1, 0)]),
     ])
     return obs_trans
Esempio n. 9
0
 def test_new_obs(self, obs_inf1, obs_inf2):
     assert set(obs_inf1.potential_new_obs()) == set(
         [GriddedPerm(Perm((0, )), ((1, 0), ))])
     assert set(obs_inf2.potential_new_obs()) == set([
         GriddedPerm(Perm((0, )), ((0, 0), )),
         GriddedPerm(Perm((0, )), ((2, 0), ))
     ])
Esempio n. 10
0
def test_remove_cells(simpleob):
    assert simpleob.remove_cells([
        (0, 0)
    ]) == GriddedPerm(Perm((1, 0)), ((2, 2), (2, 1)))
    assert simpleob.remove_cells([(0, 0), (2, 2)
                                  ]) == GriddedPerm(Perm((0, )), ((2, 1), ))
    assert simpleob.remove_cells([(0, 1), (1, 2)]) == simpleob
Esempio n. 11
0
def col_tiling():
    t = Tiling(obstructions=[
        GriddedPerm(Perm((0, 2, 1)), ((0, 0), ) * 3),
        GriddedPerm(Perm((0, 2, 1)), ((1, 0), ) * 3),
        GriddedPerm(Perm((0, 1)), ((0, 0), (1, 0))),
    ])
    return t
Esempio n. 12
0
 def enum_not_verified(self, onebyone_enum):
     t = Tiling(obstructions=[
         GriddedPerm(Perm((0, 1)), ((0, 0), (0, 1))),
         GriddedPerm(Perm((0, 1)), ((0, 0), (0, 0))),
         GriddedPerm(Perm((0, 1)), ((0, 1), (0, 1))),
     ])
     return [t, onebyone_enum]
Esempio n. 13
0
def tiling_no_trans_col():
    return Tiling(
        obstructions=[
            GriddedPerm(Perm((0, 1)), [(0, 0), (0, 1)]),
            GriddedPerm(Perm((0, 1)), [(0, 1), (0, 2)]),
        ]
    )
Esempio n. 14
0
def tiling_no_trans_row():
    return Tiling(
        obstructions=[
            GriddedPerm(Perm((0, 1)), [(0, 0), (1, 0)]),
            GriddedPerm(Perm((0, 1)), [(1, 0), (2, 0)]),
        ]
    )
Esempio n. 15
0
 def test_new_obs(self, obs_not_inf, obs_inf1, obs_inf2):
     assert obs_inf1.new_obs() == [
         GriddedPerm(Perm((0, 1)), ((0, 0), (0, 0))),
     ]
     assert obs_not_inf.new_obs() == []
     assert obs_inf2.new_obs() == [
         GriddedPerm(Perm((0, 1)), ((0, 0), (2, 0))),
     ]
Esempio n. 16
0
def test_apply_map(typicalob, simpleob):
    def cell_mapping(x):
        return (x[0] + 1, x[1] + 2)

    assert typicalob.apply_map(cell_mapping) == GriddedPerm(
        Perm((1, 0, 2, 4, 3)), ((1, 2), (1, 2), (2, 2), (2, 3), (2, 3)))
    assert simpleob.apply_map(cell_mapping) == GriddedPerm(
        Perm((1, 0, 3, 2)), ((1, 2), (1, 2), (3, 4), (3, 3)))
Esempio n. 17
0
def deflated_tiling(tiling, cell, sum_decomp=True):
    """Return tiling where cell is deflated."""
    if sum_decomp:
        extra = Obstruction.single_cell(Perm((1, 0)), cell)
    else:
        extra = Obstruction.single_cell(Perm((0, 1)), cell)
    return Tiling(requirements=tiling.requirements,
                  obstructions=tiling.obstructions + (extra, ))
Esempio n. 18
0
def tiling_simple_trans_row():
    return Tiling(
        obstructions=[
            GriddedPerm(Perm((0, 1)), [(0, 0), (1, 0)]),
            GriddedPerm(Perm((0, 1)), [(1, 0), (2, 0)]),
        ],
        requirements=[[GriddedPerm(Perm((0,)), [(1, 0)])]],
    )
Esempio n. 19
0
    def test_length_one_meshpatts_emptyness(self):
        for equivalent_shading in ([], [(0, 0)], [(1, 0)], [(0, 1), (1, 1)]):
            mp = MeshPatt(Perm((0,)), equivalent_shading)
            assert Cell(frozenset({mp}), frozenset()).is_empty()

        for nonequivalent_shading in ([(0, 0), (1, 1)], [(0, 1), (1, 0)]):
            mp = MeshPatt(Perm((0,)), nonequivalent_shading)
            assert not Cell(frozenset({mp}), frozenset()).is_empty()
Esempio n. 20
0
    def test_mixed_sorting(self):
        p1 = Perm((0, 2, 1))
        mp1 = MeshPatt(p1, [(i, i) for i in range(4)])

        p2 = Perm((1, 0))
        mp2 = MeshPatt(p2, [(2 - i, 2 - i) for i in range(3)])

        assert list(Utils.sorted({p1, mp1, p2, mp2})) == [p2, p1, mp2, mp1]
Esempio n. 21
0
 def __init__(
     self, pattern: Iterable[int] = (),
     positions: Iterable[Cell] = ()) -> None:
     self._patt = Perm(pattern)
     self._pos = tuple(positions)
     if len(self._patt) != len(self._pos):
         raise ValueError("Pattern and position list have unequal lengths.")
     self._cells: FrozenSet[Cell] = frozenset(self._pos)
Esempio n. 22
0
def simple_tiling():
    return Tiling(
        obstructions=[GriddedPerm(Perm((1, 0)), [(0, 1), (1, 0)])],
        requirements=[[
            GriddedPerm(Perm((0, 1)), [(0, 0), (1, 0)]),
            GriddedPerm(Perm((0, 1)), [(0, 0), (1, 1)]),
        ]],
    )
Esempio n. 23
0
def test_contradictory(simpleob, singlecellob, everycellob):
    assert not simpleob.contradictory()
    assert not singlecellob.contradictory()
    assert not everycellob.contradictory()
    gp = GriddedPerm(Perm((0, 1)), [(0, 1), (1, 0)])
    assert gp.contradictory()
    gp = GriddedPerm(Perm((0, 1)), [(1, 0), (0, 0)])
    assert gp.contradictory()
Esempio n. 24
0
 def enum_not_verified(self, enum_onebyone, enum_with_interleaving):
     t = Tiling(obstructions=[
         GriddedPerm(Perm((0, 1, 2)), ((0, 1), ) * 3),
         GriddedPerm(Perm((0, 1, 2)), ((1, 2), ) * 3),
         GriddedPerm(Perm((0, 1, 2)), ((1, 0), ) * 3),
         GriddedPerm(Perm((1, 2, 0)), ((0, 1), (1, 2), (1, 0))),
     ])
     return [t, enum_onebyone, enum_with_interleaving]
Esempio n. 25
0
 def enum_verified(self, enum_with_req):
     t = Tiling(obstructions=[
         GriddedPerm(Perm((0, 2, 1)), ((0, 1), ) * 3),
         GriddedPerm(Perm((0, 2, 1)), ((1, 2), ) * 3),
         GriddedPerm(Perm((0, 2, 1)), ((2, 0), ) * 3),
         GriddedPerm(Perm((1, 2, 0)), ((0, 1), (1, 2), (2, 0))),
     ])
     return [t, enum_with_req]
Esempio n. 26
0
def test_single_cell():
    gp = GriddedPerm.single_cell((0, 1, 2), (2, 3))
    assert gp.patt == Perm((0, 1, 2))
    assert gp.pos == ((2, 3), (2, 3), (2, 3))

    gp = GriddedPerm.single_cell((0, ), (45, 64))
    assert gp.patt == Perm((0, ))
    assert gp.pos == ((45, 64), )
def test_stretch_gridded_perms(placement1, placement1owncol, placement1ownrow):
    gps = [
        GriddedPerm(Perm((0, 1)), [(0, 0), (1, 1)]),
        GriddedPerm(Perm((0, 1)), [(1, 1), (2, 2)]),
    ]
    for p in (placement1, placement1ownrow, placement1owncol):
        assert set(p._stretch_gridded_perms(gps, (1, 1))) == set(
            chain.from_iterable(p._stretch_gridded_perm(gp, (1, 1)) for gp in gps)
        )
Esempio n. 28
0
 def deflation_type(gp):
     patt = gp._patt
     poss = gp._pos
     if patt == Perm((0, 2, 1)) or patt == Perm((1, 2, 0)):
         if poss[0][1] == poss[2][1] and poss[1][1] > poss[0][1]:
             return True
     if patt == Perm((1, 0, 2)) or patt == Perm((2, 0, 1)):
         if poss[0][1] == poss[2][1] and poss[1][1] < poss[0][1]:
             return True
Esempio n. 29
0
    def __init__(self, avoids=tuple(), contains=tuple(), tiling=None):
        if tiling is not None and isinstance(tiling, Tiling):
            self.tiling = tiling
        else:
            obs, reqs = stretch_av_and_co(avoids, contains, [(0, 1), (1, 0)])
            reqs.extend([[Requirement.single_cell(Perm((0,)), (0, 1))],
                         [Requirement.single_cell(Perm((0,)), (1, 0))]])

            self.tiling = Tiling(obs, reqs)
Esempio n. 30
0
 def test_potential_new_obs(self, obs_inf1, obs_not_inf):
     assert set(obs_inf1.potential_new_obs()) == set([
         GriddedPerm(Perm((0, )), ((0, 0), )),
         GriddedPerm(Perm((0, 1)), ((0, 0), (0, 0))),
         GriddedPerm(Perm((0, 1)), ((0, 0), (1, 0))),
         GriddedPerm(Perm((1, 0)), ((0, 0), (1, 0))),
     ])
     print(obs_not_inf._tiling)
     assert set(obs_not_inf.potential_new_obs()) == set([])