def get_permclass(self): if self.is_empty(): return Av(Perm((0, ))) elif self.is_point(): return PermSet(1) elif self.is_anything(): return PermSet() elif self.is_avoiding() and not self.is_containing(): return Av(self.obstructions) else: return MockAvCoPatts(self.obstructions, self.requirements)
def test_classical_basis(): p1 = PermSet([ Perm(()), Perm((0)), Perm((0, 1)), Perm((1, 0)), Perm((0, 1, 2)), Perm((0, 2, 1)), Perm((1, 0, 2)), Perm((2, 0, 1)), Perm((2, 1, 0)), Perm((0, 1, 2, 3)), Perm((0, 1, 3, 2)), Perm((0, 2, 1, 3)), Perm((0, 3, 1, 2)), Perm((0, 3, 2, 1)), Perm((1, 0, 2, 3)), Perm((1, 0, 3, 2)), Perm((2, 0, 1, 3)), Perm((2, 1, 0, 3)), Perm((3, 0, 1, 2)), Perm((3, 0, 2, 1)), Perm((3, 1, 0, 2)), Perm((3, 2, 1, 0)) ]) b1 = find_classical_basis(p1) assert b1 == [Perm((1, 2, 0)), Perm((3, 2, 0, 1))] p2 = PermSet([]) b2 = find_classical_basis(p2) assert b2 == [Perm(())] p3 = PermSet([Perm(())]) b3 = find_classical_basis(p3) assert b3 == [] p4 = PermSet([Perm(()), Perm((0))]) b4 = find_classical_basis(p4) assert b4 == [] p5 = PermSet([ Perm(()), Perm((0)), Perm((0, 1)), Perm(( 0, 1, 2, )), Perm((0, 1, 2, 3)) ]) b5 = find_classical_basis(p5) assert b5 == [Perm((1, 0))]
def __init__(self, n=None, k=None, strategy_pack=None, flogger_kwargs={'processname': 'runner'},**kwargs): self.start_tilings = [] if filename is not None: assert n == None and k == None f = open(filename, 'r') for line in f: line = line.strip() self.start_tilings.append(Tiling.from_string(line)) f.close() else: for basis in combinations(PermSet(n), k): self.start_tilings.append(Tiling([Obstruction.single_cell(patt, (0, 0)) for patt in basis])) strategy_pack.ver_strats = [verify_points] function_kwargs = {"basis": []} function_kwargs.update(kwargs.get('kwargs', dict())) CombinatorialSpecificationSearcher.__init__( self, self.start_tilings[0], strategy_pack, function_kwargs=function_kwargs, **kwargs) self.start_labels = [] for start_tiling in self.start_tilings: self.classdb.add(start_tiling, expandable=True) self.start_labels.append(self.classdb.get_label(start_tiling)) for label in self.start_labels: self.classqueue.add_to_working(label)
def internal_san_checker(): sys.stderr.write( "Starting internal sanity check with {} classes.\n".format( len(classes))) ProgressBar.create(len(classes)) for clas in classes: if len(clas) < 2: continue print('Sanity checking the class %s' % str(clas)) for l in range(1, check_len + 1): for p in PermSet(l): last = None for i in clas: if last is None: last = p.avoids(MeshPatt.unrank(classpatt, mps[i])) continue av = p.avoids(MeshPatt.unrank(classpatt, mps[i])) if av != last: print('Noooooooooooooooo') print(MeshPatt.unrank(classpatt, mps[i - 1])) print('') print(mps[i]) return last = av ProgressBar.progress() ProgressBar.finish() print("Sanity check completed.")
def find_stats(meshpatt, n): """Find the number of occurrences of meshpatt in all permutations of length up to n. Returns a list of tuples (p,s) where p is a permutation and s is the number of occurrences of meshpatt in p. """ all_perms = [] for i in range(n + 1): all_perms += list(PermSet(i)) stats = [] for p in all_perms: stats.append((p, len(list(meshpatt.occurrences_in(p))))) return stats
def external_san_checker(): for i in range(len(classes)): for j in range(i + 1, len(classes)): differ = False for l in range(1, check_len + 1): for p in PermSet(l): if p.avoids(classes[i][0]) != p.avoids(classes[j][0]): differ = True break if differ: break if not differ: print('Noooooooooooooo') print(classes[i]) print() print(classes[j])
def test_get_permclass(self): for size in range(1, 5): expected_from_empty_cell = set() permclass_empty_cell = MeshTiling.empty_cell.get_permclass() assert isinstance(permclass_empty_cell, Av) assert set(permclass_empty_cell.of_length( size)) == expected_from_empty_cell expected_from_point_cell = {Perm((0,))} if size == 1 else set() permclass_point_cell = MeshTiling.point_cell.get_permclass() assert isinstance(permclass_point_cell, PermSet) assert set(permclass_point_cell.of_length( size)) == expected_from_point_cell expected_from_anything_cell = set(PermSet(size)) permclass_anything_cell = MeshTiling.anything_cell.get_permclass() assert isinstance(permclass_anything_cell, PermSet) assert set(permclass_anything_cell.of_length( size)) == expected_from_anything_cell assert isinstance(self.mp_cell.get_permclass(), Av) assert isinstance(self.mixed_av_co_cell.get_permclass(), MockAvCoPatts)
def find_classical_basis(permset): """Find the classical basis of permset. Args: permset: The set of permutations whose classical basis is to be found. Returns list of permutations that the set avoids, if possible. """ try: # Find maximum length in the given set L = max([len(perm) for perm in permset]) except ValueError: L = 0 # Build list of all candidates for basis all_perms = [] for i in range(L+1): all_perms += list(PermSet(i)) basis = [] for p in all_perms: if p not in permset: if not any(p.contains(a) for a in basis): basis.append(p) elif not p.avoids_set(basis): return [] return basis
active, contsets = brute_coincify_len(l, active, contsets, singles) return (active, singles) def supersets_of_mesh(n, mesh): left = [(i, j) for i in range(n) for j in range(n) if (i, j) not in mesh] for sub in subsets(left): yield (mesh | set(sub)) # --------------------------------------------------------------------------- # classpatt = Perm(map(int, sys.argv[1])) mps = [int(p) for p in sys.stdin.readlines()] avoidance_set = [Perm(map(int, p)) for p in sys.argv[3:]] perm_set = PermSet.avoiding(avoidance_set) sys.stderr.write("Classical pattern {}\n".format(classpatt)) sys.stderr.write("Avoiding {}\n".format(perm_set)) # ---------- Look for surprising coincidences ---------- # # Upper bound (inclusive) on the length of permutations to look for surprising # coincidences perm_length = int(sys.argv[2]) classes, singleclasses = brute_coincify(perm_length) print() print('# Number of surprising coincidence classes {}'.format( len(classes) + len(singleclasses))) print('# Number of non-singleton coincidence classes {}'.format(len(classes))) print()