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 __init__(self, patts, classical_pattern, active): self.idmap = dict() self.pattrank = patts self.adj = [[] for _ in range(len(patts))] self.patts = [MeshPatt.unrank(classical_pattern, n) for n in patts] self.len = len(patts) self.active = active for patt in patts: if patt not in self.idmap: self.idmap[patt] = len(self.idmap) else: msg = "Element twice in class list: {}".format(patt) raise ValueError(msg)
def __init__(self, n, patt=None): self.n = n self.patt = patt self.mps = [] self.idx = {} sys.stderr.write('Generating mesh patterns\n') ProgressBar.create(2**((n + 1) * (n + 1)) * (factorial(n) if patt is None else 1)) for i, mp in enumerate(gen_meshpatts(n, patt)): ProgressBar.progress() self.mps.append(mp) self.idx[mp] = i assert MeshPatt.unrank(patt, i) == mp ProgressBar.finish()
right, top, left, bottom = patt.has_anchored_point() in_bound = set() if not right and not left and not top and not bottom: return False if right: in_bound.add(len(patt) - 1) if left: in_bound.add(0) if top: in_bound.add(inv[len(patt) - 1]) if bottom: in_bound.add(inv[0]) uf = UnionFind(len(patt)) for i in range(1, len(patt)): if all((i, j) in patt.shading for j in range(len(patt) + 1)): uf.unite(i - 1, i) if all((j, i) in patt.shading for j in range(len(patt) + 1)): uf.unite(inv[i - 1], inv[i]) # print(uf.leaders) return uf.leaders == set(uf.find(b) for b in in_bound) # cpatt = Perm(map(int, sys.stdin.readline().split())) cpatt = Perm(map(int, sys.argv[1])) mpatts = map(int, sys.stdin.readlines()) for p in mpatts: patt = MeshPatt.unrank(cpatt, p) if not is_boundary_anchored(patt) and len(patt.shading) < 10: print(patt) print()