-
Notifications
You must be signed in to change notification settings - Fork 0
Param strategies #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Param strategies #68
Changes from all commits
82917fb
0bd918f
3dd6713
caf3ac5
003963f
4008cbd
35965d7
a60ad7a
a7f2a09
ba40560
4870f93
a7a967a
2c56c72
a2a545c
7c182f4
54df492
213f71f
943e062
8b7c1e5
1528527
70321fe
51f6002
04b4ca3
c623f0f
8119360
70f7741
6beec10
dcc5c17
21833ac
c2c247d
3079b56
6e5a672
c7865e8
281754c
3419e65
3b3a894
28df247
8579547
56f6fec
fd9d5b9
612d39e
02eb19c
952cda8
ad7cea2
af70889
41a21c3
59aa891
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| """Algorithm for parameter placement""" | ||
|
|
||
| from cayley_permutations import CayleyPermutation | ||
|
|
||
| from gridded_cayley_permutations import GriddedCayleyPerm, Tiling | ||
| from gridded_cayley_permutations.point_placements import PointPlacement | ||
| from gridded_cayley_permutations.row_col_map import RowColMap | ||
|
|
||
| from mapplings import MappedTiling, Parameter, ParameterList | ||
| from .point_placement import MTRequirementPlacement | ||
|
|
||
|
|
||
| Cell = tuple[int, int] | ||
|
|
||
|
|
||
| class ParameterPlacement: | ||
| """For a given mappling and containing parameter, places the parameter | ||
| in a cell of the tiling of the mappling. Places the point of the parameter | ||
| at the given index (0 based) in the given direction.""" | ||
|
|
||
| def __init__(self, mappling: MappedTiling, param_list: ParameterList) -> None: | ||
| """cell is the cell in the tiling which the parameter will be placed into""" | ||
| assert len(param_list) == 1, "Too many Parameters in ParameterList." | ||
| assert ( | ||
| param_list in mappling.containing_parameters | ||
| ), "ParameterList does not exist." | ||
| self.mappling = mappling | ||
| new_containers = list(mappling.containing_parameters) | ||
| new_containers.remove(param_list) | ||
| self.adjusted_mappling = MappedTiling( | ||
| mappling.tiling, | ||
| mappling.avoiding_parameters, | ||
| new_containers, | ||
| mappling.enumerating_parameters, | ||
| ) | ||
| self.param = tuple(param_list)[0] | ||
|
|
||
| def param_placement(self, direction: int, index_of_pattern: int) -> MappedTiling: | ||
| """Place a parameter in the tiling. | ||
| index_of_pattern is the index of the pattern that is placed in the tiling and is 0 based. | ||
| """ | ||
| param_cell = tuple(self.param.point_cells())[index_of_pattern] | ||
| cell = (self.param.col_map[param_cell[0]], self.param.col_map[param_cell[1]]) | ||
| new_mappling = MTRequirementPlacement( | ||
| self.adjusted_mappling | ||
| ).directionless_point_placement(cell) | ||
| new_avoiding_parameters = list( | ||
| new_mappling.avoiding_parameters | ||
| ) + self.find_new_avoiding_parameters(direction, cell, param_cell) | ||
|
|
||
| new_containing_parameters = self.update_containing_parameters( | ||
| param_cell, cell, new_mappling.containing_parameters | ||
| ) | ||
| new_base = new_mappling.tiling | ||
| algo = PointPlacement(self.mappling.tiling) | ||
| point_obs, point_reqs = algo.point_obstructions_and_requirements(cell) | ||
| new_obs = new_base.obstructions + point_obs | ||
| new_reqs = new_base.requirements + point_reqs | ||
| new_base = Tiling(new_obs, new_reqs, new_base.dimensions) | ||
| return MappedTiling( | ||
| new_base, | ||
| new_avoiding_parameters, | ||
| new_containing_parameters, | ||
| new_mappling.enumerating_parameters, | ||
| ) | ||
|
|
||
| def find_new_avoiding_parameters( | ||
| self, direction: int, base_cell: Cell, param_cell: Cell | ||
| ): | ||
| """Return a list of new avoiding parameters for the new mappling.""" | ||
| cells_to_insert_in = self.cells_to_insert_point_in( | ||
| direction, base_cell, param_cell | ||
| ) | ||
| new_avoiding_parameters = [] | ||
| for cell in cells_to_insert_in: | ||
| new_ghost = PointPlacement(self.param.ghost).directionless_point_placement( | ||
| cell | ||
| ) | ||
| new_avoiding_parameters.append( | ||
| MTRequirementPlacement( | ||
| self.mappling | ||
| ).new_parameter_from_point_placed_tiling(self.param, new_ghost, cell) | ||
| ) | ||
| return new_avoiding_parameters | ||
|
|
||
| def cells_in_parameter(self, base_cell: Cell) -> tuple[Cell, ...]: | ||
| """Gets the preimage of the base cell according to the param map.""" | ||
| return self.param.map.preimage_of_cell(base_cell) | ||
|
|
||
| def cells_to_insert_point_in( | ||
| self, direction: int, base_cell: Cell, param_cell: Cell | ||
| ): | ||
| """Returns a list of cells in the parameter which a point can be | ||
| placed into for the resulting tiling to be an avoiding parameter (cells | ||
| which are not further in the given direction so that the pattern in the | ||
| parameter will be, therefore it must be avoided.)""" | ||
| all_cells = [ | ||
| cell | ||
| for cell in self.cells_in_parameter(base_cell) | ||
| if GriddedCayleyPerm(CayleyPermutation([0]), [cell]) | ||
| not in self.param.ghost.obstructions | ||
| ] | ||
| cell_of_point_being_placed = param_cell | ||
| cells_to_insert_in = [ | ||
| cell | ||
| for cell in all_cells | ||
| if PointPlacement(self.param.ghost).farther( | ||
| cell_of_point_being_placed, cell, direction | ||
| ) | ||
| ] | ||
| return cells_to_insert_in | ||
|
|
||
| def update_containing_parameters( | ||
| self, | ||
| param_cell: Cell, | ||
| base_cell: Cell, | ||
| containing_parameters: tuple[ParameterList, ...], | ||
| ) -> tuple[ParameterList, ...]: | ||
| """Remove [self.param] from containing parameters and add new | ||
| containing parameter list (one that is the identity).""" | ||
| param_to_update = Parameter(self.param.ghost, self.param.map) | ||
| point_placed_ghost = PointPlacement( | ||
| param_to_update.ghost | ||
| ).directionless_point_placement(param_cell) | ||
| new_map = self.new_containing_param_map( | ||
| param_cell, base_cell, point_placed_ghost | ||
| ) | ||
| new_containing_param = Parameter(point_placed_ghost, new_map) | ||
| return (ParameterList((new_containing_param,)),) + containing_parameters | ||
|
|
||
| def new_containing_param_map( | ||
| self, param_cell: Cell, base_cell: Cell, ghost: Tiling | ||
| ): | ||
| """Return a new RowColMap for the containing parameter that was placed.""" | ||
| new_row_map = self.adjust_dict_in_param( | ||
| param_cell, base_cell, True, ghost.dimensions[1] | ||
| ) | ||
| new_col_map = self.adjust_dict_in_param( | ||
| param_cell, base_cell, False, ghost.dimensions[0] | ||
| ) | ||
| return RowColMap(new_col_map, new_row_map) | ||
|
|
||
| def adjust_dict_in_param( | ||
| self, | ||
| middle_cell: Cell, | ||
| base_cell: Cell, | ||
| adjust_rows: bool, | ||
| dimension: int, | ||
| ): | ||
| """Update a row or col map given the cell in the new parameter where the point is placed | ||
| and the old row or col map. | ||
| If adjust_rows = 0 then it returns the new col map, if 1 then it returns the new row map. | ||
| """ | ||
| if adjust_rows: | ||
| new_map = self.param.row_map.copy() | ||
| else: | ||
| new_map = self.param.col_map.copy() | ||
| vals_in_param = set( | ||
| cell[adjust_rows] for cell in self.cells_in_parameter(base_cell) | ||
| ) | ||
| middle_val = middle_cell[adjust_rows] + 1 | ||
| for val in range(dimension): | ||
| if val not in vals_in_param: | ||
| if val > middle_val: | ||
| if val not in new_map: | ||
| new_map[val] = base_cell[adjust_rows] + 2 | ||
| else: | ||
| new_map[val] += 2 | ||
| elif val < middle_val: | ||
| new_map[val] = base_cell[adjust_rows] | ||
| elif val > middle_val: | ||
| new_map[val] = base_cell[adjust_rows] + 2 | ||
| else: | ||
| new_map[val] = base_cell[adjust_rows] + 1 | ||
| return new_map |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,11 @@ | |
| MapplingLessThanRowColSeparationStrategy, | ||
| MapplingLessThanOrEqualRowColSeparationStrategy, | ||
| MapplingCellInsertionFactory, | ||
| # ParamPlacementFactory, | ||
| # AvoiderExorcismFactory, | ||
| # ParameterInsertionFactory, | ||
|
Comment on lines
+23
to
+25
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was left by mistake? |
||
| MapplingILFactorStrategy, | ||
| MapplingInvertedILFactorStrategy, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -312,3 +317,60 @@ def insertion_row_and_col_placement(cls, rootmt: MappedTiling): | |
| symmetries=[], | ||
| iterative=False, | ||
| ) | ||
|
|
||
| @classmethod | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a point to this pack, or should it just be deleted? |
||
| def parameter_tomfoolery(cls, rootmt: MappedTiling): | ||
| """ | ||
| Create a row and column placement strategy pack which initially | ||
| makes all cells positive. | ||
| """ | ||
| return MappedTileScopePack( | ||
| initial_strats=[MapplingFactorStrategy()], | ||
| inferral_strats=[], | ||
| expansion_strats=[ | ||
| [ | ||
| MapplingLessThanRowColSeparationStrategy(), | ||
| ] | ||
| ], | ||
| ver_strats=[ | ||
| AtomStrategy(), | ||
| NoParameterVerificationStrategy(rootmt), | ||
| # MapplingVerticalInsertionEncodableVerificationStrategy(), | ||
| # MapplingHorizontalInsertionEncodableVerificationStrategy(), | ||
| ], | ||
| name="Param Nonsense", | ||
| symmetries=[], | ||
| iterative=False, | ||
| ) | ||
|
|
||
| @classmethod | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to remove these changes to ? |
||
| def pack_for_1_32( | ||
| cls, | ||
| ): | ||
| """Pack to get the 1-32 tree""" | ||
| return MappedTileScopePack( | ||
| initial_strats=[ | ||
| # MapplingFactorStrategy(), | ||
| MapplingInvertedILFactorStrategy(), | ||
| MapplingILFactorStrategy(), | ||
| ], | ||
| inferral_strats=[ | ||
| MapplingCellInsertionFactory(), | ||
| # ParamPlacementFactory(), | ||
| ], | ||
| expansion_strats=[ | ||
| [ | ||
| # ParameterInsertionFactory(ParameterList({special_param})), | ||
| MapplingPointPlacementFactory(), | ||
| ] | ||
| ], | ||
| ver_strats=[ | ||
| AtomStrategy(), | ||
| # NoParameterVerificationStrategy(rootmt), | ||
| MapplingVerticalInsertionEncodableVerificationStrategy(), | ||
| MapplingHorizontalInsertionEncodableVerificationStrategy(), | ||
| ], | ||
| name="1-32", | ||
| symmetries=[], | ||
| iterative=False, | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forgot to remove this