def classify(classes, perm, mp_cnt, uf, depth, multbox, q_check, force_len): log('Running TSA with depth=%d, multbox=%s, q_check=%s, force_len=%s' % (depth, str(multbox), str(q_check), force_len)) outfile.write('params %s\n' % repr((depth, multbox, q_check, force_len))) nclasses = [] subclasses = 0 if depth == -1: # Shading lemma for x in xrange(mp_cnt): if x != uf.find(x): outfile.write('unite %d %d\n' % (x, uf.find(x))) for cl in classes: if len(cl) >= 2: cur = sorted(cl) nclasses.append(cur) subclasses += len(cur) outfile.write('surprising %s\n' % ' '.join(map(str, cur))) else: for cl in classes: grp = { uf.find(x): [] for x in cl } for x in xrange(mp_cnt): p = uf.find(x) if p in grp: grp[p].append(x) edges = [] for i in range(len(cl)): for j in range(i+1, len(cl)): for a in grp[uf.find(cl[i])]: for b in grp[uf.find(cl[j])]: edges.append((hamming(a,b), a, b)) edges = sorted(edges) for (_,a,b) in edges: if uf.find(a) == uf.find(b): continue mp1 = MeshPattern.unrank(perm, a) mp2 = MeshPattern.unrank(perm, b) if tsa5_coincident(mp1, mp2, depth, multbox=multbox, q_check=q_check, force_len=force_len): uf.unite(a,b) outfile.write('unite %d %d\n' % (a,b)) cur = set() for x in cl: cur.add(uf.find(x)) if len(cur) <= 1: continue cur = sorted(cur) nclasses.append(cur) outfile.write('surprising %s\n' % ' '.join(map(str, cur))) subclasses += len(cur) log('Done. Classes left: %d. Total no. of subclasses: %d' % (len(nclasses), subclasses)) return nclasses
def coincify(self, maxdepth=3, multbox=True, q_check=True, force_len=None): cnt = len(self.mps) n = self.mps.n sys.stderr.write('Shading lemma coincifier\n') ProgressBar.create(len(self.mps)) for mpi, mp in enumerate(self.mps): ProgressBar.progress() if True: for mpj in range(mpi+1, len(self.mps)): mp2 = self.mps[mpj] if self.uf.find(self.mps[mp]) != self.uf.find(self.mps[mp2]) and tsa5_coincident(mp, mp2, maxdepth, multbox=multbox, q_check=q_check, force_len=force_len): self.uf.unite(self.mps[mp], self.mps[mp2]) else: poss = [] for (i,j) in mp.non_pointless_boxes(): if (i,j) not in mp.mesh: # if all_points_all_dir(mp, (i,j), maxdepth, cut=True): mp2 = mp.shade((i,j)) if self.uf.find(self.mps[mp]) != self.uf.find(self.mps[mp2]) and tsa5_coincident(mp, mp2, maxdepth, multbox=multbox, q_check=q_check, force_len=force_len): self.uf.unite(self.mps[mp], self.mps[mp2]) # for sh in mp.can_shade((i,j)): # if simultaneous and (i,j) not in mp.mesh: # poss.append((sh, set([(i,j)]))) # if not simultaneous: # self.uf.unite(self.mps[mp], self.mps[mp.shade((i,j))]) # # if simultaneous: # for i in range(n+1): # for j in range(n+1): # for di in range(-1,2): # for dj in range(-1,2): # if (di == 0) == (dj == 0): # continue # i2,j2 = (i+di, j+dj) # if 0 <= i2 < n+1 and 0 <= j2 < n+1: # for sh in mp.can_shade2((i,j),(i2,j2)): # poss.append((sh, set([(i,j),(i2,j2)]))) # # def bt(at, nm, used): # if at == len(poss): # mp2 = mp.shade(nm) # self.uf.unite(self.mps[mp], self.mps[mp2]) # return # # bt(at + 1, nm, used) # if poss[at][0] not in used and not (nm & poss[at][1]): # bt(at + 1, nm | poss[at][1], used | set([poss[at][0]])) # # bt(0, set(), set()) ProgressBar.finish()
filename = sys.argv[1] sys.stdout.write("Processing " + filename + "\n") sys.stdout.flush() patts = [] with open(filename,"r") as f: for line in f.readlines(): obj = json.loads(line) patt = MeshPattern(Permutation(obj["perm"]),map(tuple,obj["mesh"])) patts.append(patt) outfile = filename + ".out" if len(sys.argv) == 3: outfile = sys.argv[2] unexp = [] for (p1, p2) in itertools.combinations(patts,2): if not tsa5_coincident(p1,p2,5): unexp.append((p1,p2)) if len(unexp) > 0: with open(outfile,"w") as of: of.write("=======\n" + filename + "\n=======\n") for (p1,p2) in unexp: of.write("-------\n") of.write(repr(p1) + "\n") of.write(repr(p2) + "\n\n") of.write(str(p1) + "\n\n") of.write(str(p2) + "\n")