예제 #1
0
 def __call__(self, comb_class: Tiling) -> Iterator[Rule]:
     if comb_class.dimensions[0] > 1 and comb_class.dimensions[1] == 1:
         sliding = Sliding(comb_class)
         for pair in sliding.slidable_pairs():
             child = (sliding.slide_column(*pair), )
             yield SlidingStrategy(*pair, _NO_SYMMETRY)(comb_class, child)
     if self.use_symmetries:
         yield from SlidingFactory._symmetries(comb_class)
예제 #2
0
 def forward_map(
     self,
     comb_class: Tiling,
     obj: GriddedPerm,
     children: Optional[Tuple[Tiling, ...]] = None,
 ) -> Tuple[GriddedPerm]:
     maps = _AdditionalMaps.enum_to_map(self.symmetry_type,
                                        max(comb_class.dimensions))
     if self.av_123 < self.av_12:
         return (maps.g_inv(
             Sliding.slide_gp(maps.g_map(obj), self.av_123, self.av_12)), )
     return (maps.g_inv(
         Sliding.slide_gp_inverse(maps.g_map(obj), self.av_12,
                                  self.av_123)), )
예제 #3
0
 def backward_map(
     self,
     comb_class: Tiling,
     objs: Tuple[Optional[GriddedPerm], ...],
     children: Optional[Tuple[Tiling, ...]] = None,
 ) -> Iterator[GriddedPerm]:
     maps = _AdditionalMaps.enum_to_map(self.symmetry_type,
                                        max(comb_class.dimensions))
     if self.av_12 < self.av_123:
         yield from (maps.g_inv(
             Sliding.slide_gp(maps.g_map(gp), self.av_12, self.av_123))
                     for gp in objs if gp is not None)
     else:
         yield from (maps.g_inv(
             Sliding.slide_gp_inverse(maps.g_map(gp), self.av_123,
                                      self.av_12)) for gp in objs
                     if gp is not None)
예제 #4
0
 def extra_parameters(
     self,
     comb_class: Tiling,
     children: Optional[Tuple[Tiling, ...]] = None
 ) -> Tuple[Dict[str, str], ...]:
     if not comb_class.extra_parameters:
         return super().extra_parameters(comb_class, children)
     if children is None:
         children = self.decomposition_function(comb_class)
     child = children[0]
     maps = _AdditionalMaps.enum_to_map(self.symmetry_type,
                                        max(comb_class.dimensions))
     return ({
         comb_class.get_assumption_parameter(ass):
         child.get_assumption_parameter(
             Sliding.slide_assumption(ass, self.av_12, self.av_123,
                                      maps.g_map, maps.g_inv))
         for ass in comb_class.assumptions
     }, )
예제 #5
0
 def _symmetries(comb_class: Tiling) -> Iterator[Rule]:
     c, r = comb_class.dimensions
     if r == 1 and c > 1:
         tiling = comb_class.reverse()
         sliding = Sliding(tiling)
         for pair in sliding.slidable_pairs():
             maps = _AdditionalMaps.enum_to_map(_REVERSE, c)
             child = (maps.t_inv(sliding.slide_column(*pair)), )
             yield SlidingStrategy(*pair, _REVERSE)(comb_class, child)
     elif r > 1 and c == 1:
         tiling = comb_class.rotate90()
         sliding = Sliding(tiling)
         for pair in sliding.slidable_pairs():
             maps = _AdditionalMaps.enum_to_map(_ROTATE, r)
             child = (maps.t_inv(sliding.slide_column(*pair)), )
             yield SlidingStrategy(*pair, _ROTATE)(comb_class, child)
         tiling = tiling.reverse()
         sliding = Sliding(tiling)
         for pair in sliding.slidable_pairs():
             maps = _AdditionalMaps.enum_to_map(_ROTATE_AND_REVERSE, r)
             child = (maps.t_inv(sliding.slide_column(*pair)), )
             yield SlidingStrategy(*pair, _ROTATE_AND_REVERSE)(comb_class,
                                                               child)
예제 #6
0
 def decomposition_function(self, comb_class: Tiling) -> Tuple[Tiling]:
     """Return the slidded tiling if it slides, otherwise None."""
     maps = _AdditionalMaps.enum_to_map(self.symmetry_type,
                                        max(comb_class.dimensions))
     sliding = Sliding(maps.t_map(comb_class))
     return (maps.t_inv(sliding.slide_column(self.av_12, self.av_123)), )
예제 #7
0
def generate_all_slided_tilings(tiling):
    sliding = Sliding(tiling)
    for av_12, av_123 in sliding.slidable_pairs():
        yield sliding.slide_column(av_12, av_123)
예제 #8
0
def test_slide():
    tcases = [
        (
            Tiling(
                obstructions=(
                    GriddedPerm((0, 1), ((2, 0), (2, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (0, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (1, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (2, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (1, 0), (1, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (1, 0), (2, 0))),
                    GriddedPerm((0, 1, 2), ((1, 0), (1, 0), (1, 0))),
                    GriddedPerm((0, 1, 2), ((1, 0), (1, 0), (2, 0))),
                ),
                requirements=(),
                assumptions=(),
            ),
            Tiling(
                obstructions=(
                    GriddedPerm((0, 1), ((1, 0), (1, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (0, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (1, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (2, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (1, 0), (2, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (2, 0), (2, 0))),
                    GriddedPerm((0, 1, 2), ((1, 0), (2, 0), (2, 0))),
                    GriddedPerm((0, 1, 2), ((2, 0), (2, 0), (2, 0))),
                ),
                requirements=(),
                assumptions=(),
            ),
            (1, 2),
            7,
        ),
        (
            Tiling(
                obstructions=(
                    GriddedPerm((0, 1, 2, 3, 4), ((1, 0),) * 5),
                    GriddedPerm((0, 1), ((3, 0), (3, 0))),
                    GriddedPerm((0, 1, 2, 3, 4), ((1, 0),) * 4 + ((3, 0),)),
                    GriddedPerm((4, 3, 2, 1), ((0, 0),) * 4),
                    GriddedPerm((2, 3, 1, 0), ((2, 0),) * 4),
                    GriddedPerm((0, 2, 1), ((4, 0),) * 3),
                    GriddedPerm((1, 2, 0), ((1, 0), (2, 0), (4, 0))),
                    GriddedPerm((2, 1, 0), ((2, 0), (3, 0), (4, 0))),
                    GriddedPerm(
                        (4, 1, 2, 3, 0), ((0, 0), (0, 0), (1, 0), (1, 0), (4, 0))
                    ),
                    GriddedPerm(
                        (4, 1, 2, 3, 0), ((0, 0), (0, 0), (1, 0), (3, 0), (4, 0))
                    ),
                )
            ),
            Tiling(
                obstructions=(
                    GriddedPerm((0, 1, 2, 3, 4), ((3, 0),) * 5),
                    GriddedPerm((0, 1), ((1, 0), (1, 0))),
                    GriddedPerm((0, 1, 2, 3, 4), ((1, 0),) + ((3, 0),) * 4),
                    GriddedPerm((4, 3, 2, 1), ((0, 0),) * 4),
                    GriddedPerm((2, 3, 1, 0), ((2, 0),) * 4),
                    GriddedPerm((0, 2, 1), ((4, 0),) * 3),
                    GriddedPerm((1, 2, 0), ((1, 0), (2, 0), (4, 0))),
                    GriddedPerm((2, 1, 0), ((2, 0), (3, 0), (4, 0))),
                    GriddedPerm(
                        (4, 1, 2, 3, 0), ((0, 0), (0, 0), (3, 0), (3, 0), (4, 0))
                    ),
                    GriddedPerm(
                        (4, 1, 2, 3, 0), ((0, 0), (0, 0), (1, 0), (3, 0), (4, 0))
                    ),
                )
            ),
            (1, 3),
            6,
        ),
        (
            Tiling(
                obstructions=(
                    GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (0, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (1, 0))),
                    GriddedPerm((0, 1), ((1, 0), (1, 0))),
                    GriddedPerm((1, 2, 3, 0), ((0, 0), (0, 0), (2, 0), (2, 0))),
                    GriddedPerm((1, 2, 3, 0), ((0, 0), (1, 0), (2, 0), (2, 0))),
                ),
                requirements=(((GriddedPerm((0, 2, 1), ((2, 0), (2, 0), (2, 0))),),)),
            ),
            Tiling(
                obstructions=(
                    GriddedPerm((0, 1, 2), ((1, 0), (1, 0), (1, 0))),
                    GriddedPerm((0, 1, 2), ((0, 0), (1, 0), (1, 0))),
                    GriddedPerm((0, 1), ((0, 0), (0, 0))),
                    GriddedPerm((1, 2, 3, 0), ((1, 0), (1, 0), (2, 0), (2, 0))),
                    GriddedPerm((1, 2, 3, 0), ((0, 0), (1, 0), (2, 0), (2, 0))),
                ),
                requirements=(((GriddedPerm((0, 2, 1), ((2, 0), (2, 0), (2, 0))),),)),
            ),
            (),  # default
            7,
        ),
    ]

    for t1, t2, cols, up_to in tcases:
        visited = set()
        expected = set(t2.gridded_perms(up_to))
        for gp in t1.gridded_perms(up_to):
            sl = Sliding.slide_gp(gp, *cols)
            assert sl not in visited
            visited.add(sl)
            assert sl in expected
            expected.remove(sl)
        assert len(expected) == 0

        visited = set()
        expected = set(t1.gridded_perms(up_to))
        for gp in t2.gridded_perms(up_to):
            sl = Sliding.slide_gp_inverse(gp, *cols)
            assert sl not in visited
            visited.add(sl)
            assert sl in expected
            expected.remove(sl)
        assert len(expected) == 0