def positive_left_right_requirements(self): """ Return the pair of requirements that ensures the left contains at least one point, and the right contains at least one point. """ left, right = [], [] for (x, y) in self._tiling.active_cells: if self._fuse_row and y == self._row_idx: left.append(GriddedPerm.single_cell(Perm((0,)), (x, y))) right.append(GriddedPerm.single_cell(Perm((0,)), (x, y + 1))) if not self._fuse_row and x == self._col_idx: left.append(GriddedPerm.single_cell(Perm((0,)), (x, y))) right.append(GriddedPerm.single_cell(Perm((0,)), (x + 1, y))) return tuple(sorted(left)), tuple(sorted(right))
def _get_cell_insertion_input( ) -> Tuple[Tiling, VerificationTactics, GriddedPerm]: data = _get_request_json() try: tiling = decode_key(data["tiling"]) verification_tactics = VerificationTactics.from_response_dictionary( data["verify"]) x: int = data["x"] y: int = data["y"] patt: str = data["patt"] except (TypeError, KeyError, ValueError, TilingDecodeException) as exc: raise BadRequest() from exc if not (isinstance(x, int) and isinstance(y, int) and isinstance(patt, str)): raise BadRequest() if not patt.isdecimal(): raise BadRequest() _x, _y = tiling.dimensions if x < 0 or x >= _x or y < 0 or y >= _y: raise BadRequest() n, value_set = len(patt), set(map(int, patt)) if len(value_set) != n or not all( i in value_set for i in (range(n) if 0 in value_set else range(1, n + 1))): raise BadRequest() return ( tiling, verification_tactics, GriddedPerm.single_cell(Perm.to_standard(patt), (x, y)), )
def new_assumption(self): """ Return the assumption that needs to counted in order to enumerate. """ return TrackingAssumption( GriddedPerm.single_cell(Perm((0,)), cell) for cell in self._tiling.active_cells if (self._fuse_row and cell[1] == self._row_idx) or (not self._fuse_row and cell[0] == self._col_idx) )
def new_assumption(self): """ Return the assumption that needs to be counted in order to enumerate. """ fcell = self.first_cell scell = self.second_cell gps = (GriddedPerm.single_cell(Perm((0,)), fcell),) if self._fuse_row: sum_ob = GriddedPerm(Perm((1, 0)), (scell, fcell)) else: sum_ob = GriddedPerm(Perm((1, 0)), (fcell, scell)) if sum_ob in self._tiling.obstructions: return SumComponentAssumption(gps) return SkewComponentAssumption(gps)
def new_positive_requirement(self): cells = [ (x, y) for (x, y) in self._tiling.active_cells if (self._fuse_row and y == self._row_idx) or (not self._fuse_row and x == self._col_idx) ] if self._positive_left and self._positive_right: cells.sort() res = [] for idx, c1 in enumerate(cells): for c2 in cells[idx:]: res.append(GriddedPerm(Perm((0, 1)), (c1, c2))) if self._fuse_row: res.append(GriddedPerm(Perm((1, 0)), (c1, c2))) else: res.append(GriddedPerm(Perm((1, 0)), (c2, c1))) return sorted(res) if self._positive_left or self._positive_right: return sorted(GriddedPerm.single_cell(Perm((0,)), cell) for cell in cells) raise ValueError("no positive left right requirement")
def _get_add_assumption_input( ) -> Tuple[Tiling, VerificationTactics, List[GriddedPerm]]: data = _get_request_json() try: tiling = decode_key(data["tiling"]) verification_tactics = VerificationTactics.from_response_dictionary( data["verify"]) pos: List[List[int]] = data["pos"] except (TypeError, KeyError, ValueError, TilingDecodeException) as exc: raise BadRequest() from exc if not isinstance(pos, list) or len(pos) == 0: raise BadRequest() _x, _y = tiling.dimensions gps: List[GriddedPerm] = [] for coord in pos: if not isinstance(coord, list) or len(coord) != 2: raise BadRequest() x, y = coord if not (isinstance(x, int) and isinstance(y, int)): raise BadRequest() if x < 0 or y < 0 or x >= _x or y >= _y: raise BadRequest() gps.append(GriddedPerm.single_cell((0, ), (x, y))) return tiling, verification_tactics, gps