Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def mesh_contains_cl_patt_many_shadings(perm, S, patt, Rs):
for candidate_indices in patt.occurrences_in(perm):
candidate = [perm[index] for index in candidate_indices]
hit_boxes = []
x = 0
for element in perm:
if element in candidate:
x += 1
continue
y = sum(1 for candidate_elt in candidate if candidate_elt < element)
hit_boxes.append((x, y))
shit_boxes = set(hit_boxes)
for R in Rs:
if shit_boxes.intersection(R) == set([]):
candidate_sub_mesh_patt = MeshPatt(perm, S).sub_mesh_pattern(
candidate_indices
)
if set(R) <= set(candidate_sub_mesh_patt.shading):
return True
return False
[(len_calc_patts[0], x, y) for y in sg[len_calc_patts[0]][x]]
for x in sg[len_calc_patts[0]]
]
)
)
if report:
print("There are " + str(len(monitor)) + " potential bases to monitor")
print("Starting the tests")
if detailed_report:
print("The monitors are")
for i, m in enumerate(monitor):
print("Monitor {}".format(i))
for patt_id in m:
mpatt = dict_numbs_to_patts[patt_id]
print(MeshPatt(mpatt[0], mpatt[1]).ascii_plot())
print()
print("-----------")
# perm_len_min should be 1+len_calc_patts[0]
for L in range(perm_len_min, perm_len_max + 1):
# Restricting to the pattern lengths that are smaller than the length of
# the permutations we are looking at
appropriate_len_calc_patts = list(
filter(lambda x: x < L, len_calc_patts)
) # TODO Should this be <= in 2020?
# When we try to expand with larger patterns below we need to now if L is
# available as a length of forbidden patterns
L_is_a_key = False
if L in SG.keys():
L_is_a_key = True
if detailed_report:
print("-----------------------------------")
print("Testing the permutation " + str(perm))
dict_numbs_to_perm_avoids_patt = dict()
saviors = []
for ell in appropriate_len_calc_patts:
for patt_i in sg[ell].keys():
for sh_i in sg[ell][patt_i]:
mpat = dict_numbs_to_patts[(ell, patt_i, sh_i)]
# Checking whether perm avoids mpat
if perm.avoids(MeshPatt(mpat[0], mpat[1])):
dict_numbs_to_perm_avoids_patt[(ell, patt_i, sh_i)] = True
else:
dict_numbs_to_perm_avoids_patt[(ell, patt_i, sh_i)] = False
saviors.append((ell, patt_i, sh_i))
if detailed_report:
print(
"When monitors fail below they will extended with "
+ str(len(saviors))
+ " saviors"
)
print("They are " + str(saviors))
# If L is available as a length of forbidden patterns (checked above) we
# need to know if perm is one of the underlying classical patterns of that
# length
def show_me_basis(b, dict_numbs_to_patts):
"""
To see the patterns in a basis b
show_me_basis(b, dict_numbs_to_patts)
"""
print("\nDisplaying the patterns in the basis\n")
# dfo = display_forb_output(SG)
for i in b:
mpatt = dict_numbs_to_patts[i]
print(MeshPatt(mpatt[0], mpatt[1]).ascii_plot())
print()
the permutation induced by the indices and a region is shaded if and only
if the corresponding region of self is fully shaded.
Exampes:
>>> shading = frozenset({(3, 2), (1, 3), (4, 2), (0, 3), (1, 2),
... (4, 3)})
>>> MeshPatt(Perm((3, 2, 1, 0)),
... shading).sub_mesh_pattern((0, 1, 3))
MeshPatt(Perm((2, 1, 0)), [(0, 2), (1, 2), (3, 2)])
>>> MeshPatt(Perm((2, 3, 1, 0)),
... shading).sub_mesh_pattern((1, 2, 3))
MeshPatt(Perm((2, 1, 0)), [(3, 2)])
"""
indices = sorted(indices)
if not indices:
return MeshPatt()
n = len(self)
pattern = Perm.to_standard(self.pattern[index] for index in indices)
vertical = [0]
vertical.extend(index + 1 for index in indices)
vertical.append(n + 1)
horizontal = [0]
horizontal.extend(sorted(self.pattern[index] + 1 for index in indices))
horizontal.append(n + 1)
shading = frozenset(
(x, y)
for x in range(len(pattern) + 1)
for y in range(len(pattern) + 1)
if (
self.is_shaded(
(vertical[x], horizontal[y]),
(vertical[x + 1] - 1, horizontal[y + 1] - 1),
def inverse(self) -> "MeshPatt":
"""Returns the inverse of the meshpatt, that is the meshpatt with the
underlying classical pattern as the inverse and the shadings hold the
same relation between the points. This is equivalent to flipping the
pattern over the diagonal.
Examples:
>>> MeshPatt(Perm((0,)), frozenset({(0, 1)})).inverse()
MeshPatt(Perm((0,)), [(1, 0)])
"""
return MeshPatt(self.pattern.inverse(), ((y, x) for (x, y) in self.shading))
>>> p.add_point((2, 0), shade_dir=DIR_SOUTH)
MeshPatt(Perm((1, 2, 0, 3)), [(1, 0), (1, 1), (2, 0), (2, 2), (3, 0), (3, 2), \
(4, 3)])
"""
assert pos not in self.shading
x, y = pos
new_shading = self._add_point_base_shading(x, y)
if shade_dir == DIR_EAST:
new_shading.update(((x + 1, y), (x + 1, y + 1)))
elif shade_dir == DIR_NORTH:
new_shading.update(((x, y + 1), (x + 1, y + 1)))
elif shade_dir == DIR_WEST:
new_shading.update(((x, y), (x, y + 1)))
elif shade_dir == DIR_SOUTH:
new_shading.update(((x, y), (x + 1, y)))
return MeshPatt(self._add_point_new_perm(x, y), new_shading)
def Baxter(perm):
return perm.avoids(
MeshPatt(Perm((1, 3, 0, 2)), [(2, 2)]), MeshPatt(Perm((2, 0, 3, 1)), [(2, 2)])
)