From d3a8e7c2aec0246861cf7f1d89c54ae064940bd8 Mon Sep 17 00:00:00 2001 From: Christian Bean Date: Mon, 23 Sep 2019 12:59:42 +0000 Subject: [PATCH 1/4] Update strategies with new algo on tilings --- .../strategies/batch_strategies/__init__.py | 6 +- .../list_requirement_placements.py | 237 +++--------------- .../equivalence_strategies/__init__.py | 3 +- .../equivalence_strategies/isolate_points.py | 21 +- .../partial_point_placements.py | 110 +------- .../point_placements.py | 121 +-------- 6 files changed, 70 insertions(+), 428 deletions(-) diff --git a/tilescopethree/strategies/batch_strategies/__init__.py b/tilescopethree/strategies/batch_strategies/__init__.py index 45907e9ad..b662f589b 100644 --- a/tilescopethree/strategies/batch_strategies/__init__.py +++ b/tilescopethree/strategies/batch_strategies/__init__.py @@ -4,7 +4,11 @@ all_requirement_insertions, all_row_insertions, root_requirement_insertion) from .list_requirement_placements import (col_placements, + partial_col_placements, + partial_row_and_col_placements, + partial_row_placements, requirement_list_placement, - row_placements) + row_placements, + row_and_col_placements) from .requirement_corroboration import requirement_corroboration from .targeted_cell_insertion import targeted_cell_insertion diff --git a/tilescopethree/strategies/batch_strategies/list_requirement_placements.py b/tilescopethree/strategies/batch_strategies/list_requirement_placements.py index 759be4f09..0b5eaf0b2 100644 --- a/tilescopethree/strategies/batch_strategies/list_requirement_placements.py +++ b/tilescopethree/strategies/batch_strategies/list_requirement_placements.py @@ -1,208 +1,47 @@ -from itertools import chain +from itertools import product -from comb_spec_searcher import Rule -from permuta import Perm -from permuta.misc import DIR_EAST, DIR_NONE, DIR_NORTH, DIR_SOUTH, DIR_WEST -from tilings import Obstruction, Requirement, Tiling +from comb_spec_searcher import BatchRule +from permuta.misc import DIR_EAST, DIR_NORTH, DIR_SOUTH, DIR_WEST +from tilings.algorithms import RequirementPlacement def requirement_list_placement(tiling, **kwargs): """Places all requirements on the tiling in every direction.""" - for req in tiling.requirements: - for direction in [DIR_NORTH, DIR_SOUTH, DIR_EAST, DIR_WEST]: - tilings = place_requirement_list(tiling, req, direction) - if tilings is None: - continue - yield Rule( - formal_step=("Place requirement {} in direction {}." - "".format(req, direction)), - comb_classes=tilings, - ignore_parent=False, - possibly_empty=[True for _ in tilings], - inferable=[True for _ in tilings], - workable=[True for _ in tilings], - constructor='disjoint') - - -def row_placements(tiling, row=True, positive=True, regions=False, **kwargs): - """Places the points in a row (or col if row=False) in the given - direction.""" - if row: - x = tiling.dimensions[1] - y = tiling.dimensions[0] - only_cell_in_col = tiling.only_cell_in_col - directions = [DIR_NORTH, DIR_SOUTH] - else: - x = tiling.dimensions[0] - y = tiling.dimensions[1] - only_cell_in_col = tiling.only_cell_in_row - directions = [DIR_EAST, DIR_WEST] - - rows = range(x) - if kwargs.get("index") is not None: - rows = [kwargs.get("index")] - if kwargs.get("direction") is not None: - directions = [kwargs["direction"]] - if regions: - forward_maps = [] - - direction = kwargs.get('direction') - if direction is not None: - if row: - if direction == DIR_NORTH: - directions = [DIR_NORTH] - elif direction == DIR_SOUTH: - directions = [DIR_SOUTH] - else: - raise ValueError("Can't place rows in direction.") - else: - if direction == DIR_EAST: - directions = [DIR_EAST] - elif direction == DIR_WEST: - directions = [DIR_WEST] - else: - raise ValueError("Can't place cols in direction.") - - for i in rows: - place = True - cells_in_row = [] - for j in range(y): - cell = (j, i) if row else (i, j) - if positive and cell not in tiling.positive_cells: - place = False - break - cells_in_row.append(cell) - if place: - if (len(cells_in_row) != 1 or - not cells_in_row[0] in tiling.point_cells or - not only_cell_in_col(cells_in_row[0])): - req_list = tuple(Requirement(Perm((0,)), (cell,)) - for cell in cells_in_row) - if not positive: - """Adding the empty row case.""" - empty_row_tiling = Tiling(tiling.obstructions + - tuple(Obstruction(Perm((0,)), - (cell,)) - for cell in cells_in_row), - tiling.requirements) - if regions: - forward_maps.append({c: frozenset([c]) - for c in tiling.active_cells}) - for direction in directions: - if regions: - tilings, placed_maps = place_requirement_list( - tiling, req_list, direction, - regions=regions) - if not positive: - tilings = [empty_row_tiling] + tilings - forward_maps.extend(placed_maps) - yield tilings, forward_maps - else: - tilings = place_requirement_list(tiling, req_list, - direction) - if not positive: - tilings = [empty_row_tiling] + tilings - yield Rule( - formal_step=("Placing {} {} in direction {}." - "".format("row" if row else "col", - i, direction, - i, direction, int(positive))), - comb_classes=tilings, - ignore_parent=False, - possibly_empty=[True for _ in tilings], - inferable=[True for _ in tilings], - workable=[True for _ in tilings], - constructor='disjoint') + req_placement = RequirementPlacement(tiling) + directions = (DIR_EAST, DIR_NORTH, DIR_SOUTH, DIR_WEST) + for req, direction in product(tiling.requirements, directions): + yield BatchRule(req_placement.place_point_of_req_list(req, direction), + "Inserting {} point of requirement list ({})".format( + req_placement._direction_string(direction), + ", ".join(str(r) for r in req))) +def row_placements(tiling, **kwargs): + yield from RequirementPlacement(tiling).all_row_placement_rules() def col_placements(tiling, **kwargs): - yield from row_placements(tiling, row=False, **kwargs) - - -def place_requirement_list(tiling, req_list, direction, regions=False): - """Return the list of tilings obtained by placing the direction-most point - of a requirement list. This represents a batch strategy, where the - direction-most point of each requirement in the list is placed.""" - # Compute the points furthest in the given direction. - min_points = minimum_points(req_list, direction) - if len([c for _, c in min_points]) != len(set([c for _, c in min_points])): - # Can't handle list requirements with more than req farthest in the - # direction in same cell. - return None - # For each tiling, compute the tiling where this point is placed furthest - # in that direction. - res = [] - if regions: - forward_maps = [] - for (idx, cell), req in zip(min_points, req_list): - # Placing the forced occurrence of the point in the requirement - new_req, forced_obstructions = req.place_forced_point(idx, direction) - assert len(new_req) == 1 - # Add the forced obstruction to ensure no other requirement has a point - # further in that direction. - forced_obstructions = (forced_obstructions + - list(chain.from_iterable( - r.other_req_forced_point(cell, direction) - for r in req_list if r != req))) - # New indices of the point - point_cell = (cell[0] + 1, cell[1] + 1) - # The set of new obstructions, consisting of the forced obstructions, - # other obstructions where the point placement has been taken into - # account and the 12, 21 in the cell. - newobs = forced_obstructions + list(chain.from_iterable( - ob.place_point(cell, DIR_NONE) for ob in tiling.obstructions)) + [ - Obstruction.single_cell(Perm((0, 1)), point_cell), - Obstruction.single_cell(Perm((1, 0)), point_cell)] - # The rest of the requirements - other_reqs = [reqs for reqs in tiling.requirements if reqs != req_list] - # The new requirements, consisting of the requirement with the point - # placed, other requirements where point placement has been taken into - # account and the point requirement in the cell. - newreqs = [list(chain.from_iterable(r.place_point(cell, DIR_NONE) - for r in reqs)) - for reqs in other_reqs] + [new_req] + [ - [Requirement.single_cell(Perm((0,)), point_cell)]] - placed_tiling = Tiling(newobs, newreqs) - res.append(placed_tiling) - if regions: - def cell_map(c): - mindex, minval = c - maxdex = mindex + 1 - maxval = minval + 1 - if mindex >= cell[0]: - maxdex += 2 - if minval >= cell[1]: - maxval += 2 - if mindex > cell[0]: - mindex += 2 - if minval > cell[1]: - minval += 2 - return frozenset([(x, y) for x in range(mindex, maxdex) - for y in range(minval, maxval)]) - forward_maps.append({c: cell_map(c) for c in tiling.active_cells}) - if regions: - return res, forward_maps - else: - return res - - -def minimum_points(req_list, direction): - """Return a list of tuple containing the index and cell of the point in the - requirement furthest to the geiven direction.""" - res = [] - if direction == DIR_WEST: - res = [(0, req.pos[0]) for req in req_list] - elif direction == DIR_EAST: - res = [(len(req) - 1, req.pos[-1]) for req in req_list] - elif direction == DIR_SOUTH: - for req in req_list: - mindex = req.patt.index(0) - res.append((mindex, req.pos[mindex])) - elif direction == DIR_NORTH: - for req in req_list: - maxdex = req.patt.index(0) - res.append((maxdex, req.pos[maxdex])) - else: - raise ValueError("Must choose north, south, east or west.") + yield from RequirementPlacement(tiling).all_col_placement_rules() + +def row_and_col_placements(tiling, **kwargs): + req_placements = RequirementPlacement(tiling) + yield from req_placements.all_row_placement_rules() + yield from req_placements.all_col_placement_rules() + +def partial_row_placements(tiling, **kwargs): + req_placements = (RequirementPlacement(tiling, own_row=False), + RequirementPlacement(tiling, own_col=False)) + for req_placement in req_placements: + yield from req_placement.all_row_placement_rules() + +def partial_col_placements(tiling, **kwargs): + req_placements = (RequirementPlacement(tiling, own_row=False), + RequirementPlacement(tiling, own_col=False)) + for req_placement in req_placements: + yield from req_placement.all_col_placement_rules() + +def partial_row_and_col_placements(tiling, **kwargs): + req_placements = (RequirementPlacement(tiling, own_row=False), + RequirementPlacement(tiling, own_col=False)) + for req_placement in req_placements: + yield from req_placement.all_row_placement_rules() + yield from req_placement.all_col_placement_rules() - return res diff --git a/tilescopethree/strategies/equivalence_strategies/__init__.py b/tilescopethree/strategies/equivalence_strategies/__init__.py index eda40e79c..8bf92279f 100644 --- a/tilescopethree/strategies/equivalence_strategies/__init__.py +++ b/tilescopethree/strategies/equivalence_strategies/__init__.py @@ -3,4 +3,5 @@ from .fusion_with_interleaving import fusion_with_interleaving from .partial_point_placements import (partial_point_placement, partial_requirement_placement) -from .point_placements import point_placement, requirement_placement +from .point_placements import (all_placements, point_placement, + requirement_placement) diff --git a/tilescopethree/strategies/equivalence_strategies/isolate_points.py b/tilescopethree/strategies/equivalence_strategies/isolate_points.py index d97776675..2e03b4b45 100644 --- a/tilescopethree/strategies/equivalence_strategies/isolate_points.py +++ b/tilescopethree/strategies/equivalence_strategies/isolate_points.py @@ -1,19 +1,12 @@ from comb_spec_searcher import EquivalenceRule from permuta.misc import DIR_WEST -from tilescopethree.strategies.batch_strategies.point_placements import \ - place_point_of_requirement +from tilings.algorithms import RequirementPlacement def point_isolations(tiling, **kwargs): - point_cells = tiling.point_cells - for ri, reqs in enumerate(tiling.requirements): - if len(reqs) > 1: - continue - cell = reqs[0].is_point_perm() - if cell is None or cell not in point_cells: - continue - yield EquivalenceRule( - formal_step=("Isolating point at {} into its own row and " - "column").format(cell), - # Direction does not matter - comb_class=place_point_of_requirement(tiling, ri, 0, DIR_WEST)) + req_placement = RequirementPlacement(tiling) + for cell in tiling.point_cells: + if not tiling.only_cell_in_row_and_col(): + isolated_tiling = req_placement.place_point_in_cell(cell, DIR_WEST) + yield EquivalenceRule("Isolate point at cell {}.".format(cell), + isolated_tiling) \ No newline at end of file diff --git a/tilescopethree/strategies/equivalence_strategies/partial_point_placements.py b/tilescopethree/strategies/equivalence_strategies/partial_point_placements.py index 81c9c7e3c..57839f3db 100644 --- a/tilescopethree/strategies/equivalence_strategies/partial_point_placements.py +++ b/tilescopethree/strategies/equivalence_strategies/partial_point_placements.py @@ -1,83 +1,4 @@ -from itertools import chain - -from comb_spec_searcher import EquivalenceRule -from permuta import Perm -from permuta.misc import (DIR_EAST, DIR_NONE, DIR_NORTH, DIR_SOUTH, DIR_WEST, - DIRS) -from tilings import Obstruction, Requirement, Tiling - - -def opposite_dir(DIR): - if DIR == DIR_WEST: - return DIR_EAST - if DIR == DIR_EAST: - return DIR_WEST - if DIR == DIR_NORTH: - return DIR_SOUTH - if DIR == DIR_SOUTH: - return DIR_NORTH - return DIR_NONE - - -def partial_place_point_of_requirement(tiling, req_index, point_index, - force_dir): - """ - Places the point at point_index in requirement at req_index into tiling on - its own row or onto its own column depending on force_dir. - """ - if len(tiling.requirements[req_index]) > 1: - raise ValueError( - "Requirement list at {} contains more than 1 requirement.".format( - req_index)) - # Determine if placing onto own row or column - row = (force_dir == DIR_NORTH or force_dir == DIR_SOUTH) - # The requirement - requirement = tiling.requirements[req_index][0] - # The cell containing the point - cell = requirement.pos[point_index] - # The rest of the requirements - other_reqs = [tiling.requirements[i] - for i in range(len(tiling.requirements)) - if i != req_index] - # Placing the forced occurrence of the point in the requirement - new_req, forced_obstructions = requirement.partial_place_forced_point( - point_index, force_dir) - assert len(new_req) == 1 - # New indices of the point. - point_cell = (cell[0] if row else cell[0] + 1, - cell[1] + 1 if row else cell[1]) - # The set of new obstructions, consisting of the forced obstructions, other - # obstructions where the point placement has been taken into account and - # the 12, 21 in the cell. - newobs = forced_obstructions + list(chain.from_iterable( - ob.place_point(cell, DIR_NONE, partial=True, row=row) - for ob in tiling.obstructions)) + [ - Obstruction.single_cell(Perm((0, 1)), point_cell), - Obstruction.single_cell(Perm((1, 0)), point_cell)] - # If a point cell, make sure neighbouring cells are empty by adding the - # point obstructions. - if cell in tiling.point_cells: - if force_dir == DIR_EAST or force_dir == DIR_WEST: - newobs = (newobs + - [Obstruction.single_cell( - Perm((0,)), (point_cell[0] + 1, point_cell[1])), - Obstruction.single_cell( - Perm((0,)), (point_cell[0] - 1, point_cell[1]))]) - elif force_dir == DIR_NORTH or force_dir == DIR_SOUTH: - newobs = (newobs + - [Obstruction.single_cell( - Perm((0,)), (point_cell[0], point_cell[1] + 1)), - Obstruction.single_cell( - Perm((0,)), (point_cell[0], point_cell[1] - 1))]) - # The new requirements, consisting of the requirement with the point - # placed, other requirements where point placement has been taken into - # account and the point requirement in the cell. - newreqs = [list(chain.from_iterable(req.place_point(cell, DIR_NONE, - partial=True, row=row) - for req in reqs)) - for reqs in other_reqs] + [new_req] + [ - [Requirement.single_cell(Perm((0,)), point_cell)]] - return Tiling(obstructions=newobs, requirements=newreqs) +from tilings.algorithms import RequirementPlacement def partial_requirement_placement(tiling, **kwargs): @@ -90,31 +11,10 @@ def partial_requirement_placement(tiling, **kwargs): points of the requirement. The strategy then returns all tilings where the point has been partially placed with a force. """ - point_cells = tiling.point_cells - point_only = kwargs.get('point_only') - for ri, reqs in enumerate(tiling.requirements): - if len(reqs) > 1: - continue - if reqs[0].is_point_perm() in point_cells: - cell = reqs[0].pos[0] - directions = [] - if not tiling.only_cell_in_row(cell): - directions.extend((DIR_NORTH, DIR_SOUTH)) - if not tiling.only_cell_in_col(cell): - directions.extend((DIR_EAST, DIR_WEST)) - else: - directions = DIRS - if point_only and reqs[0].is_point_perm() is None: - continue - for i in range(len(reqs[0])): - for DIR in directions: - placedtiling = partial_place_point_of_requirement( - tiling, ri, i, DIR) - yield EquivalenceRule( - formal_step=("Partially placing point {} of requirement {}" - " with force {}").format( - (i, reqs[0].patt[i]), str(reqs[0]), DIR), - comb_class=placedtiling) + req_placements = (RequirementPlacement(tiling, own_row=False), + RequirementPlacement(tiling, own_col=False)) + for req_placement in req_placements: + yield from req_placement.all_requirement_placement_rules() def partial_point_placement(tiling, **kwargs): diff --git a/tilescopethree/strategies/equivalence_strategies/point_placements.py b/tilescopethree/strategies/equivalence_strategies/point_placements.py index 72917d016..41098407c 100644 --- a/tilescopethree/strategies/equivalence_strategies/point_placements.py +++ b/tilescopethree/strategies/equivalence_strategies/point_placements.py @@ -1,86 +1,4 @@ -from itertools import chain - -from comb_spec_searcher import Rule -from permuta import Perm -from permuta.misc import (DIR_EAST, DIR_NONE, DIR_NORTH, DIR_SOUTH, DIR_WEST, - DIRS) -from tilings import Obstruction, Requirement, Tiling - - -def opposite_dir(DIR): - if DIR == DIR_WEST: - return DIR_EAST - if DIR == DIR_EAST: - return DIR_WEST - if DIR == DIR_NORTH: - return DIR_SOUTH - if DIR == DIR_SOUTH: - return DIR_NORTH - return DIR_NONE - - -def place_point_of_requirement(tiling, req_index, point_index, force_dir, - **kwargs): - """ - Places the point at point_index in requirement at req_index into tiling. - """ - if len(tiling.requirements[req_index]) > 1: - raise ValueError( - "Requirement list at {} contains more than 1 requirement.".format( - req_index)) - # The requirement - requirement = tiling.requirements[req_index][0] - # The cell containing the point - cell = requirement.pos[point_index] - # The rest of the requirements - other_reqs = [tiling.requirements[i] - for i in range(len(tiling.requirements)) - if i != req_index] - # Placing the forced occurrence of the point in the requirement - new_req, forced_obstructions = requirement.place_forced_point( - point_index, force_dir) - assert len(new_req) == 1 - # New indices of the point - point_cell = (cell[0] + 1, cell[1] + 1) - - # The set of new obstructions, consisting of the forced obstructions, other - # obstructions where the point placement has been taken into account and - # the 12, 21 in the cell. - newobs = forced_obstructions + list(chain.from_iterable( - ob.place_point(cell, DIR_NONE) for ob in tiling.obstructions)) + [ - Obstruction.single_cell(Perm((0, 1)), point_cell), - Obstruction.single_cell(Perm((1, 0)), point_cell)] - # The new requirements, consisting of the requirement with the point - # placed, other requirements where point placement has been taken into - # account and the point requirement in the cell. - newreqs = [list(chain.from_iterable(req.place_point(cell, DIR_NONE) - for req in reqs)) - for reqs in other_reqs] + [new_req] + [ - [Requirement.single_cell(Perm((0,)), point_cell)]] - - placed_tiling = Tiling(obstructions=newobs, requirements=newreqs) - if kwargs.get('regions', False): - def cell_map(c): - mindex, minval = c - maxdex = mindex + 1 - maxval = minval + 1 - if mindex >= cell[0]: - maxdex += 2 - if minval >= cell[1]: - maxval += 2 - if mindex > cell[0]: - mindex += 2 - if minval > cell[1]: - minval += 2 - return set([placed_tiling.forward_map[(x, y)] - for x in range(mindex, maxdex) - for y in range(minval, maxval) - if ((x, y) in placed_tiling.forward_map and - placed_tiling.forward_map[(x, y)] in - placed_tiling.active_cells)]) - return [placed_tiling], [{c: cell_map(c) for c in tiling.active_cells}] - - return placed_tiling +from tilings.algorithms import RequirementPlacement def requirement_placement(tiling, **kwargs): @@ -92,30 +10,7 @@ def requirement_placement(tiling, **kwargs): points of the requirement. The strategy then returns all tilings where the point has been placed with a force. """ - point_cells = tiling.point_cells - point_only = kwargs.get('point_only') - ignore_parent = kwargs.get('ignore_parent', False) - for ri, reqs in enumerate(tiling.requirements): - if len(reqs) > 1: - continue - if (reqs[0].is_point_perm() in point_cells and - tiling.only_cell_in_row_and_col(reqs[0].is_point_perm())): - continue - if point_only and reqs[0].is_point_perm() is None: - continue - for i in range(len(reqs[0])): - for DIR in DIRS: - placedtiling = place_point_of_requirement(tiling, ri, i, DIR) - yield Rule( - formal_step=("Placing point {} of requirement {} " - "with force {}").format( - (i, reqs[0].patt[i]), str(reqs[0]), DIR), - comb_classes=[placedtiling], - ignore_parent=ignore_parent, - inferable=[True], - possibly_empty=[True], - workable=[True], - constructor='equiv') + yield from RequirementPlacement(tiling).all_requirement_placement_rules() def point_placement(tiling, **kwargs): @@ -126,4 +21,14 @@ def point_placement(tiling, **kwargs): requirement lists. For each of them, it returns a new tiling where the point has been placed with a force. """ - yield from requirement_placement(tiling, point_only=True) + yield from RequirementPlacement(tiling).all_point_placement_rules() + +def all_placements(tiling, **kwargs): + req_placements = (RequirementPlacement(tiling), + RequirementPlacement(tiling, own_row=False), + RequirementPlacement(tiling, own_col=False)) + for req_placement in req_placements: + yield from req_placement.all_point_placement_rules() + yield from req_placement.all_requirement_placement_rules() + yield from req_placement.all_col_placement_rules() + yield from req_placement.all_row_placement_rules() From 37d575117831514dc5fab17bb7802de12e52df52 Mon Sep 17 00:00:00 2001 From: Christian Bean Date: Tue, 24 Sep 2019 10:57:49 +0000 Subject: [PATCH 2/4] change all strats pack --- tilescopethree/strategy_packs_v2.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tilescopethree/strategy_packs_v2.py b/tilescopethree/strategy_packs_v2.py index 1e76be352..429610a60 100644 --- a/tilescopethree/strategy_packs_v2.py +++ b/tilescopethree/strategy_packs_v2.py @@ -7,8 +7,8 @@ all_requirement_insertions, all_row_insertions) from tilescopethree.strategies import col_placements as col_placements_strat -from tilescopethree.strategies import (database_verified, elementary_verified, - factor, fusion, +from tilescopethree.strategies import (all_placements, database_verified, + elementary_verified, factor, fusion, fusion_with_interleaving, globally_verified, obstruction_transitivity, @@ -125,15 +125,8 @@ def all_the_strategies(cls, length=1): obstruction_transitivity], expansion_strats=[[partial(all_cell_insertions, maxreqlen=length), - all_row_insertions, - all_col_insertions, all_requirement_insertions], - [partial(row_placements_strat, - positive=False), - partial(col_placements_strat, - positive=False), - partial_requirement_placement, - requirement_placement]], + [all_placements]], name="all_the_strategies") @classmethod From 322816fb28238c841b326a0d07f696220bd0a2e2 Mon Sep 17 00:00:00 2001 From: Christian Bean Date: Tue, 24 Sep 2019 16:50:57 +0000 Subject: [PATCH 3/4] updated point placement tests --- .../test_point_placements.py | 62 ++++++++++++++----- .../strategies/batch_strategies/__init__.py | 4 +- .../list_requirement_placements.py | 7 ++- .../equivalence_strategies/isolate_points.py | 2 +- .../point_placements.py | 1 + tilescopethree/strategy_packs_v2.py | 5 +- 6 files changed, 60 insertions(+), 21 deletions(-) diff --git a/tests/strategies/equivalence_strategies/test_point_placements.py b/tests/strategies/equivalence_strategies/test_point_placements.py index 6775de67d..4050d977c 100644 --- a/tests/strategies/equivalence_strategies/test_point_placements.py +++ b/tests/strategies/equivalence_strategies/test_point_placements.py @@ -1,8 +1,6 @@ from permuta import Perm from permuta.misc import DIR_EAST, DIR_NORTH, DIR_SOUTH, DIR_WEST, DIRS from tilescopethree.strategies import point_placement, requirement_placement -from tilescopethree.strategies.equivalence_strategies.point_placements import \ - place_point_of_requirement from tilings import Obstruction, Requirement, Tiling pytest_plugins = [ @@ -14,17 +12,19 @@ def test_point_placement(diverse_tiling, no_point_tiling): + print(no_point_tiling) + print(no_point_tiling.positive_cells) strats = list(point_placement(diverse_tiling)) - assert len(strats) == 3 * len(DIRS) - + assert len(strats) == 5 * len(DIRS) strats = list(requirement_placement(no_point_tiling)) - assert len(strats) == 3 * len(DIRS) + assert len(strats) == 9 * len(DIRS) strats = list(point_placement(no_point_tiling)) - assert len(strats) == 0 + assert len(strats) == 3 * len(DIRS) def test_place_point_of_requirement_point_only(diverse_tiling): - tiling = place_point_of_requirement(diverse_tiling, 0, 0, DIR_WEST) + tiling = diverse_tiling.place_point_of_gridded_permutation( + diverse_tiling.requirements[0][0], 0, DIR_WEST) assert tiling == Tiling( obstructions=[ Obstruction(Perm((0,)), [(1, 0)]), @@ -53,13 +53,43 @@ def test_place_point_of_requirement_point_only(diverse_tiling): Requirement(Perm((0, 2, 1)), [(0, 3), (0, 4), (1, 4)]), Requirement(Perm((0, 2, 1)), [(0, 3), (0, 4), (3, 4)])]]) - assert tiling == place_point_of_requirement(diverse_tiling, 0, 0, DIR_EAST) - assert tiling == place_point_of_requirement( - diverse_tiling, 0, 0, DIR_NORTH) - assert tiling == place_point_of_requirement( - diverse_tiling, 0, 0, DIR_SOUTH) + assert tiling == diverse_tiling.place_point_of_gridded_permutation( + diverse_tiling.requirements[0][0], 0, DIR_EAST) + assert tiling == diverse_tiling.place_point_of_gridded_permutation( + diverse_tiling.requirements[0][0], 0, DIR_NORTH) + assert tiling == diverse_tiling.place_point_of_gridded_permutation( + diverse_tiling.requirements[0][0], 0, DIR_SOUTH) - tiling = place_point_of_requirement(diverse_tiling, 1, 0, DIR_WEST) + print(Tiling( + obstructions=[ + Obstruction(Perm((0,)), [(2, 0)]), + Obstruction(Perm((0,)), [(2, 2)]), + Obstruction(Perm((0, 1)), [(1, 0), (1, 0)]), + Obstruction(Perm((0, 1)), [(1, 0), (1, 2)]), + Obstruction(Perm((0, 1)), [(1, 2), (1, 2)]), + Obstruction(Perm((0, 1)), [(3, 1), (3, 1)]), + Obstruction(Perm((0, 1)), [(2, 3), (2, 3)]), + Obstruction(Perm((0, 1)), [(2, 3), (4, 3)]), + Obstruction(Perm((0, 1)), [(4, 3), (4, 3)]), + Obstruction(Perm((1, 0)), [(1, 0), (1, 0)]), + Obstruction(Perm((1, 0)), [(1, 2), (1, 0)]), + Obstruction(Perm((1, 0)), [(1, 2), (1, 2)]), + Obstruction(Perm((1, 0)), [(3, 1), (3, 1)]), + Obstruction(Perm((1, 0)), [(2, 3), (2, 3)]), + Obstruction(Perm((1, 0)), [(2, 3), (4, 3)]), + Obstruction(Perm((1, 0)), [(4, 3), (4, 3)]), + Obstruction(Perm((0, 1, 2)), [(0, 0), (1, 3), (1, 3)]), + Obstruction(Perm((0, 2, 3, 1)), [(0, 2), (1, 3), (1, 3), (4, 2)])], + requirements=[ + [Requirement(Perm((0,)), [(3, 1)])], + [Requirement(Perm((0,)), [(1, 0)]), + Requirement(Perm((0,)), [(1, 2)])], + [Requirement(Perm((0,)), [(2, 3)]), + Requirement(Perm((0,)), [(4, 3)])], + [Requirement(Perm((1, 0)), [(0, 4), (0, 3)]), + Requirement(Perm((0, 2, 1)), [(0, 3), (0, 4), (1, 4)])]])) + tiling = diverse_tiling.place_point_of_gridded_permutation( + diverse_tiling.requirements[1][0], 0, DIR_WEST) assert tiling == Tiling( obstructions=[ Obstruction(Perm((0,)), [(2, 0)]), @@ -90,14 +120,16 @@ def test_place_point_of_requirement_point_only(diverse_tiling): Requirement(Perm((0, 2, 1)), [(0, 3), (0, 4), (1, 4)])]]) tiling = Tiling(requirements=[[Requirement(Perm((0,)), [(0, 0)])]]) - assert place_point_of_requirement(tiling, 0, 0, DIR_SOUTH) == Tiling( + assert tiling.place_point_of_gridded_permutation(tiling.requirements[0][0], + 0, DIR_SOUTH) == Tiling( obstructions=[Obstruction(Perm((0, 1)), [(0, 0), (0, 0)]), Obstruction(Perm((1, 0)), [(0, 0), (0, 0)])], requirements=[[Requirement(Perm((0,)), [(0, 0)])]]) def test_place_point_of_requirement(no_point_tiling): - tiling = place_point_of_requirement(no_point_tiling, 2, 1, DIR_WEST) + tiling = no_point_tiling.place_point_of_gridded_permutation( + no_point_tiling.requirements[2][0], 1, DIR_WEST) tiling2 = Tiling( obstructions=[ Obstruction(Perm((0, 1)), [(0, 1), (1, 3)]), diff --git a/tilescopethree/strategies/batch_strategies/__init__.py b/tilescopethree/strategies/batch_strategies/__init__.py index b662f589b..b0baf226f 100644 --- a/tilescopethree/strategies/batch_strategies/__init__.py +++ b/tilescopethree/strategies/batch_strategies/__init__.py @@ -8,7 +8,7 @@ partial_row_and_col_placements, partial_row_placements, requirement_list_placement, - row_placements, - row_and_col_placements) + row_and_col_placements, + row_placements) from .requirement_corroboration import requirement_corroboration from .targeted_cell_insertion import targeted_cell_insertion diff --git a/tilescopethree/strategies/batch_strategies/list_requirement_placements.py b/tilescopethree/strategies/batch_strategies/list_requirement_placements.py index 0b5eaf0b2..4a16f7547 100644 --- a/tilescopethree/strategies/batch_strategies/list_requirement_placements.py +++ b/tilescopethree/strategies/batch_strategies/list_requirement_placements.py @@ -15,33 +15,38 @@ def requirement_list_placement(tiling, **kwargs): req_placement._direction_string(direction), ", ".join(str(r) for r in req))) + def row_placements(tiling, **kwargs): yield from RequirementPlacement(tiling).all_row_placement_rules() + def col_placements(tiling, **kwargs): yield from RequirementPlacement(tiling).all_col_placement_rules() + def row_and_col_placements(tiling, **kwargs): req_placements = RequirementPlacement(tiling) yield from req_placements.all_row_placement_rules() yield from req_placements.all_col_placement_rules() + def partial_row_placements(tiling, **kwargs): req_placements = (RequirementPlacement(tiling, own_row=False), RequirementPlacement(tiling, own_col=False)) for req_placement in req_placements: yield from req_placement.all_row_placement_rules() + def partial_col_placements(tiling, **kwargs): req_placements = (RequirementPlacement(tiling, own_row=False), RequirementPlacement(tiling, own_col=False)) for req_placement in req_placements: yield from req_placement.all_col_placement_rules() + def partial_row_and_col_placements(tiling, **kwargs): req_placements = (RequirementPlacement(tiling, own_row=False), RequirementPlacement(tiling, own_col=False)) for req_placement in req_placements: yield from req_placement.all_row_placement_rules() yield from req_placement.all_col_placement_rules() - diff --git a/tilescopethree/strategies/equivalence_strategies/isolate_points.py b/tilescopethree/strategies/equivalence_strategies/isolate_points.py index 2e03b4b45..7d8549321 100644 --- a/tilescopethree/strategies/equivalence_strategies/isolate_points.py +++ b/tilescopethree/strategies/equivalence_strategies/isolate_points.py @@ -9,4 +9,4 @@ def point_isolations(tiling, **kwargs): if not tiling.only_cell_in_row_and_col(): isolated_tiling = req_placement.place_point_in_cell(cell, DIR_WEST) yield EquivalenceRule("Isolate point at cell {}.".format(cell), - isolated_tiling) \ No newline at end of file + isolated_tiling) diff --git a/tilescopethree/strategies/equivalence_strategies/point_placements.py b/tilescopethree/strategies/equivalence_strategies/point_placements.py index 41098407c..361f74aeb 100644 --- a/tilescopethree/strategies/equivalence_strategies/point_placements.py +++ b/tilescopethree/strategies/equivalence_strategies/point_placements.py @@ -23,6 +23,7 @@ def point_placement(tiling, **kwargs): """ yield from RequirementPlacement(tiling).all_point_placement_rules() + def all_placements(tiling, **kwargs): req_placements = (RequirementPlacement(tiling), RequirementPlacement(tiling, own_row=False), diff --git a/tilescopethree/strategy_packs_v2.py b/tilescopethree/strategy_packs_v2.py index 429610a60..8187dd64f 100644 --- a/tilescopethree/strategy_packs_v2.py +++ b/tilescopethree/strategy_packs_v2.py @@ -4,11 +4,12 @@ from comb_spec_searcher import StrategyPack from comb_spec_searcher.utils import get_func_name from tilescopethree.strategies import (all_cell_insertions, all_col_insertions, + all_placements, all_requirement_insertions, all_row_insertions) from tilescopethree.strategies import col_placements as col_placements_strat -from tilescopethree.strategies import (all_placements, database_verified, - elementary_verified, factor, fusion, +from tilescopethree.strategies import (database_verified, elementary_verified, + factor, fusion, fusion_with_interleaving, globally_verified, obstruction_transitivity, From 50533c6f8ad8cf29a263dfe0624e253b4eebc415 Mon Sep 17 00:00:00 2001 From: Christian Bean Date: Wed, 2 Oct 2019 14:39:54 +0000 Subject: [PATCH 4/4] removing prints --- .../strategies/equivalence_strategies/test_point_placements.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/strategies/equivalence_strategies/test_point_placements.py b/tests/strategies/equivalence_strategies/test_point_placements.py index 4050d977c..ee765e8f4 100644 --- a/tests/strategies/equivalence_strategies/test_point_placements.py +++ b/tests/strategies/equivalence_strategies/test_point_placements.py @@ -12,8 +12,6 @@ def test_point_placement(diverse_tiling, no_point_tiling): - print(no_point_tiling) - print(no_point_tiling.positive_cells) strats = list(point_placement(diverse_tiling)) assert len(strats) == 5 * len(DIRS) strats = list(requirement_placement(no_point_tiling))