Skip to content

Commit cc45fe8

Browse files
authored
Merge pull request #44 from PermutaTriangle/obs-inf
use new obstruction inferral algorithm
2 parents a4c8e38 + f81c21b commit cc45fe8

File tree

1 file changed

+5
-35
lines changed

1 file changed

+5
-35
lines changed
Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from comb_spec_searcher import InferralRule
22
from permuta import Perm
33
from tilings import Obstruction, Tiling
4+
from tilings.algorithms import EmptyCellInferral, SubobstructionInferral
45

56

67
def empty_cell_inferral(tiling, **kwargs):
@@ -9,43 +10,12 @@ def empty_cell_inferral(tiling, **kwargs):
910
The strategy considers each active but non-positive cell and inserts a
1011
point requirement. If the resulting tiling is empty, then a point
1112
obstruction can be added into the cell, i.e. the cell is empty."""
12-
active = set(tiling.active_cells)
13-
positive = set(tiling.positive_cells)
14-
empty_cells = []
15-
for cell in active - positive:
16-
reqtil = tiling.insert_cell(cell)
17-
if reqtil.is_empty():
18-
empty_cells.append(cell)
19-
newobs = [Obstruction.single_cell(Perm((0,)), cell)
20-
for cell in empty_cells]
21-
return InferralRule(
22-
"The cells {} are empty".format(", ".join(map(str, empty_cells))),
23-
Tiling(obstructions=tiling.obstructions + tuple(newobs),
24-
requirements=tiling.requirements))
13+
eci = EmptyCellInferral(tiling)
14+
return eci.rule()
2515

2616

2717
def subobstruction_inferral(tiling, **kwargs):
2818
"""Return tiling created by adding all subobstructions which can be
2919
added."""
30-
subobs = set()
31-
for ob in tiling.obstructions:
32-
subobs.update(ob.all_subperms())
33-
newobs = []
34-
if subobs:
35-
merged_tiling = tiling.merge(remove_empty=False)
36-
for ob in sorted(subobs, key=len):
37-
if can_add_obstruction(ob, merged_tiling):
38-
newobs.append(ob)
39-
merged_tiling = Tiling(merged_tiling.obstructions + (ob,),
40-
merged_tiling.requirements,
41-
remove_empty=False)
42-
if newobs:
43-
return InferralRule("Added the obstructions {}.".format(newobs),
44-
Tiling(tiling.obstructions + tuple(newobs),
45-
tiling.requirements))
46-
47-
48-
def can_add_obstruction(obstruction, tiling):
49-
"""Return true if obstruction can be added to tiling."""
50-
return tiling.add_requirement(obstruction.patt,
51-
obstruction.pos).merge().is_empty()
20+
soi = SubobstructionInferral(tiling)
21+
return soi.rule()

0 commit comments

Comments
 (0)