Skip to content

Commit 973cade

Browse files
committed
Migrate requirement corroboration
1 parent f9b6df3 commit 973cade

File tree

2 files changed

+21
-43
lines changed

2 files changed

+21
-43
lines changed

tilescopethree/strategies/batch_strategies/cell_insertion.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from itertools import chain
2-
from typing import List, Optional
1+
from typing import Iterable, List, Optional
32

3+
from comb_spec_searcher import Rule
44
from permuta import Perm
55
from tilings import Tiling
66
from tilings.algorithms import (CellInsertion, ColInsertion, CrossingInsertion,
@@ -11,7 +11,7 @@
1111
def all_cell_insertions(tiling: Tiling, maxreqlen: int = 1, extra_basis:
1212
Optional[List[Perm]] = None,
1313
ignore_parent: bool = False,
14-
**kwargs):
14+
**kwargs) -> Iterable[Rule]:
1515
"""
1616
The cell insertion strategy.
1717
@@ -25,7 +25,7 @@ def all_cell_insertions(tiling: Tiling, maxreqlen: int = 1, extra_basis:
2525
extra_basis).rules(ignore_parent)
2626

2727

28-
def root_requirement_insertion(tiling, **kwargs):
28+
def root_requirement_insertion(tiling, **kwargs) -> Iterable[Rule]:
2929
"""
3030
The cell insertion strategy performed only on 1 by 1 tilings.
3131
"""
@@ -34,7 +34,7 @@ def root_requirement_insertion(tiling, **kwargs):
3434
yield from all_cell_insertions(tiling, **kwargs)
3535

3636

37-
def all_point_insertions(tiling, **kwargs):
37+
def all_point_insertions(tiling, **kwargs) -> Iterable[Rule]:
3838
"""
3939
The cell insertion strategy using only points.
4040
"""
@@ -43,28 +43,31 @@ def all_point_insertions(tiling, **kwargs):
4343

4444
def all_requirement_extensions(tiling: Tiling, maxreqlen: int = 2,
4545
extra_basis: Optional[List[Perm]] = None,
46-
ignore_parent: bool = False, **kwargs):
46+
ignore_parent: bool = False,
47+
**kwargs) -> Iterable[Rule]:
4748
"""
4849
Insert longer requirements in to cells which contain a requirement
4950
"""
5051
yield from RequirementExtension(tiling, maxreqlen,
5152
extra_basis).rules(ignore_parent)
5253

5354

54-
def all_row_insertions(tiling: Tiling, ignore_parent: bool = False, **kwargs):
55+
def all_row_insertions(tiling: Tiling, ignore_parent: bool = False,
56+
**kwargs) -> Iterable[Rule]:
5557
"""Insert a list requirement into every possibly empty row."""
5658
yield from RowInsertion(tiling).rules(ignore_parent)
5759

5860

59-
def all_col_insertions(tiling, ignore_parent: bool = False, **kwargs):
61+
def all_col_insertions(tiling, ignore_parent: bool = False,
62+
**kwargs) -> Iterable[Rule]:
6063
"""Insert a list requirement into every possibly empty column."""
6164
yield from ColInsertion(tiling).rules(ignore_parent)
6265

6366

6467
def all_requirement_insertions(tiling: Tiling, maxreqlen: int = 1,
6568
extra_basis: Optional[List[Perm]] = None,
6669
ignore_parent: bool = False,
67-
**kwargs):
70+
**kwargs) -> Iterable[Rule]:
6871
"""
6972
Insert all possible requirements the obstruction allows if the tiling does
7073
not have requirements.
@@ -76,7 +79,7 @@ def all_requirement_insertions(tiling: Tiling, maxreqlen: int = 1,
7679

7780

7881
def all_factor_insertions(tiling: Tiling, ignore_parent: bool = False,
79-
**kwargs):
82+
**kwargs) -> Iterable[Rule]:
8083
"""
8184
Insert all proper factor of the requirement or obstructions on the tiling.
8285
"""
Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
"""
22
Module containing the requirement corroboration strategy.
33
"""
4+
from typing import Iterable
5+
46
from comb_spec_searcher import Rule
5-
from tilings import Obstruction, Requirement, Tiling
7+
from tilings import Tiling
8+
from tilings.algorithms import RequirementCorroboration
69

710

8-
def requirement_corroboration(tiling, basis, **kwargs):
11+
def requirement_corroboration(tiling: Tiling, ignore_parent: bool = True,
12+
**kwargs) -> Iterable[Rule]:
913
"""
1014
The requirement corroboration strategy.
1115
12-
The requirement corrobation strategy is a batch strategy that considers
16+
The requirement corroboration strategy is a batch strategy that considers
1317
each requirement of each requirement list. For each of these requirements,
1418
the strategy returns two tilings; one where the requirement has been turned
1519
into an obstruction and another where the requirement has been singled out
@@ -21,33 +25,4 @@ def requirement_corroboration(tiling, basis, **kwargs):
2125
that avoid the requirement, must therefore satisfy another requirement from
2226
the same list and hence the requirement list must be of length at least 2.
2327
"""
24-
for reqs in tiling.requirements:
25-
if len(reqs) == 1:
26-
continue
27-
for req in reqs:
28-
yield Rule(
29-
formal_step="Inserting requirement {}.".format(str(req)),
30-
comb_classes=gp_insertion(tiling, req),
31-
ignore_parent=True,
32-
possibly_empty=[True, True],
33-
workable=[True for _ in range(2)],
34-
inferable=[True for _ in range(2)],
35-
constructor='disjoint')
36-
37-
38-
def pos_str(pos):
39-
return "/".join("{},{}".format(c[0], c[1]) for c in pos)
40-
41-
42-
def gp_insertion(tiling, gp, regions=False):
43-
"""Return a list of size 2, where the first tiling avoids the gridded perm
44-
gp and the second contains gp."""
45-
tilings = [tiling.add_obstruction(gp.patt, gp.pos),
46-
tiling.add_requirement(gp.patt, gp.pos)]
47-
48-
if regions:
49-
forward_maps = [{c: frozenset([c]) for c in tiling.active_cells},
50-
{c: frozenset([c]) for c in tiling.active_cells}]
51-
return tilings, forward_maps
52-
else:
53-
return tilings
28+
yield from RequirementCorroboration(tiling).rules(ignore_parent)

0 commit comments

Comments
 (0)