コード例 #1
0
 def req_lists_to_insert(self, tiling: Tiling) -> Iterator[ListRequirement]:
     active = tiling.active_cells
     bdict = tiling.cell_basis()
     for cell, length in product(active, range(1, self.maxreqlen + 1)):
         basis = bdict[cell][0] + self.extra_basis
         yield from ((GriddedPerm.single_cell(patt, cell), )
                     for patt in Av(basis).of_length(length)
                     if not any(patt in perm for perm in bdict[cell][1]))
コード例 #2
0
 def req_lists_to_insert(self, tiling: Tiling) -> Iterator[ListRequirement]:
     bdict = tiling.cell_basis()
     cell_with_req = ((cell, obs, reqlist[0])
                      for cell, (obs, reqlist) in bdict.items()
                      if len(reqlist) == 1)
     for cell, obs, curr_req in cell_with_req:
         for length in range(len(curr_req) + 1, self.maxreqlen + 1):
             for patt in Av(obs + self.extra_basis).of_length(length):
                 if curr_req in patt:
                     yield (GriddedPerm.single_cell(patt, cell), )
コード例 #3
0
 def decomposition_function(
         self, comb_class: Tiling) -> Optional[Tuple[Tiling, ...]]:
     """
     The rule as the root as children if one of the cell of the tiling is the root.
     """
     if self.verified(comb_class):
         if not self.basis:
             return ()
         for obs, _ in comb_class.cell_basis().values():
             if frozenset(obs) in self.symmetries:
                 return (Tiling.from_perms(self.basis), )
         return ()
     return None
コード例 #4
0
    def pack(comb_class: Tiling) -> StrategyPack:
        if any(isinstance(ass, ComponentAssumption) for ass in comb_class.assumptions):
            raise InvalidOperationError(
                "Can't find generating function with component assumption."
            )
        # pylint: disable=import-outside-toplevel
        from tilings.tilescope import TileScopePack

        assert comb_class.dimensions == (1, 1)
        basis, _ = comb_class.cell_basis()[(0, 0)]
        if any(
            any(p.contains(patt) for patt in basis)
            for p in [
                Perm((0, 2, 1)),
                Perm((1, 2, 0)),
                Perm((1, 0, 2)),
                Perm((2, 0, 1)),
            ]
        ):
            # subclass of Av(231) or a symmetry, use point placements!
            return TileScopePack.point_and_row_and_col_placements().add_verification(
                BasicVerificationStrategy(), replace=True
            )
        if is_insertion_encodable_maximum(basis):
            return TileScopePack.regular_insertion_encoding(3)
        if is_insertion_encodable_rightmost(basis):
            return TileScopePack.regular_insertion_encoding(2)
        # if it is the class or positive class
        if not comb_class.requirements or (
            len(comb_class.requirements) == 1
            and len(comb_class.requirements[0]) == 1
            and len(comb_class.requirements[0][0]) <= 2
        ):
            if basis in ([Perm((0, 1, 2))], [Perm((2, 1, 0))]):
                # Av(123) or Av(321) - use fusion!
                return (
                    TileScopePack.row_and_col_placements(row_only=True)
                    .make_fusion(tracked=True)
                    .add_basis(basis)
                )
            if (Perm((0, 1, 2)) in basis or Perm((2, 1, 0)) in basis) and all(
                len(p) <= 4 for p in basis
            ):
                # is a subclass of Av(123) avoiding patterns of length <= 4
                # experimentally showed that such clsses always terminates
                return TileScopePack.row_and_col_placements().add_basis(basis)
        raise InvalidOperationError(
            "Cannot get a specification for one by one verification for "
            f"subclass Av({basis})"
        )
コード例 #5
0
    def req_lists_to_insert(self, tiling: Tiling) -> Iterator[ListRequirement]:
        if self.one_cell_only:
            assert self.maxreqlen == 1 and self.ignore_parent
            cells = sorted(
                frozenset(tiling.active_cells) - frozenset(tiling.positive_cells)
            )
            if cells:
                yield (GriddedPerm.single_cell((0,), cells[0]),)
            return

        active = tiling.active_cells
        bdict = tiling.cell_basis()
        for cell, length in product(active, range(1, self.maxreqlen + 1)):
            basis = bdict[cell][0] + self.extra_basis
            patterns = Av(basis).of_length(length) if basis else Perm.of_length(length)
            yield from (
                (GriddedPerm.single_cell(patt, cell),)
                for patt in patterns
                if not any(patt in perm for perm in bdict[cell][1])
            )
コード例 #6
0
 def has_topmost_insertion_encoding(tiling: Tiling) -> bool:
     return tiling.dimensions[1] == 1 and all(
         is_insertion_encodable_maximum(basis)
         for basis, _ in tiling.cell_basis().values()
     )
コード例 #7
0
 def has_rightmost_insertion_encoding(tiling: Tiling) -> bool:
     return tiling.dimensions[0] == 1 and all(
         is_insertion_encodable_rightmost(basis)
         for basis, _ in tiling.cell_basis().values()
     )
コード例 #8
0
 def verified(self, comb_class: Tiling) -> bool:
     cell_bases = (frozenset(obs) for obs, _ in comb_class.cell_basis().values())
     return not bool(self.symmetries.intersection(cell_bases))