def test5(showme=1, findallmatches=1): domaingraph, domaincells, morseset, vertexmap, outedges, walldomains, varsaffectedatwall, varnames, threshnames = tc.test5( ) extendedmorsegraph, extendedmorsecells = pp.makeExtendedMorseSetDomainGraph( vertexmap, morseset, domaingraph, domaincells) newoutedges, wallthresh, newwalldomains, booleanoutedges = pp.makeWallGraphFromDomainGraph( len(vertexmap), extendedmorsegraph, extendedmorsecells) newvarsaffectedatwall = pp.varsAtWalls(threshnames, newwalldomains, wallthresh, varnames) wallinfo = makeWallInfo(newoutedges, newwalldomains, newvarsaffectedatwall) wallinfo = pp.truncateExtendedWallGraph(booleanoutedges, newoutedges, wallinfo) patternnames, patternmaxmin, originalpatterns = fp.parsePatterns() patterns = pp.translatePatterns(varnames, patternnames, patternmaxmin, cyclic=1) match = matchPattern(patterns[0][0], wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(6, 0, 3, 4, 5, 10, 9, 8, 6), (7, 1, 0, 3, 4, 5, 10, 9, 7), (7, 2, 4, 5, 10, 9, 7)]) if showme and not findallmatches: print match[0] in [(6, 0, 3, 4, 5, 10, 9, 8, 6), (7, 1, 0, 3, 4, 5, 10, 9, 7), (7, 2, 4, 5, 10, 9, 7)] match = matchPattern(patterns[1][0], wallinfo, cyclic=1, findallmatches=findallmatches) if showme: print 'None' in match
def test1(): outedges, walldomains, varsaffectedatwall = tc.test1() wallinfo = wl.makeWallInfo(outedges, walldomains, varsaffectedatwall) print wallinfo[(0, 1)] == [(3, ('um', ))] print wallinfo[(1, 3)] == [(2, ('Mu', ))] print wallinfo[(3, 2)] == [(0, ('dM', ))] print wallinfo[(2, 0)] == [(1, ('md', ))]
def test1(): outedges,walldomains,varsaffectedatwall=tc.test1() wallinfo = wl.makeWallInfo(outedges,walldomains,varsaffectedatwall) print wallinfo[(0,1)]==[(3,('um',))] print wallinfo[(1,3)]==[(2,('Mu',))] print wallinfo[(3,2)]==[(0,('dM',))] print wallinfo[(2,0)]==[(1,('md',))]
def test2(): outedges, walldomains, varsaffectedatwall = tc.test2() wallinfo = wl.makeWallInfo(outedges, walldomains, varsaffectedatwall) print set(wallinfo[(0, 1)]) == set([(3, ('um', )), (4, ('um', ))]) print wallinfo[(3, 2)] == [(0, ('dM', ))] print wallinfo[(5, 2)] == [(0, ('dM', ))] print wallinfo[(1, 4)] == [(6, ('uu', ))]
def test2(): outedges,walldomains,varsaffectedatwall=tc.test2() wallinfo = wl.makeWallInfo(outedges,walldomains,varsaffectedatwall) print set(wallinfo[(0,1)])==set([(3,('um',)),(4,('um',))]) print wallinfo[(3,2)]==[(0,('dM',))] print wallinfo[(5,2)]==[(0,('dM',))] print wallinfo[(1,4)]==[(6,('uu',))]
def test6(showme=1, findallmatches=1): domaingraph, domaincells, morseset, vertexmap, outedges, walldomains, varsaffectedatwall, varnames, threshnames = tc.test6( ) extendedmorsegraph, extendedmorsecells = pp.makeExtendedMorseSetDomainGraph( vertexmap, morseset, domaingraph, domaincells) newoutedges, wallthresh, newwalldomains, booleanoutedges = pp.makeWallGraphFromDomainGraph( len(vertexmap), extendedmorsegraph, extendedmorsecells) newvarsaffectedatwall = pp.varsAtWalls(threshnames, newwalldomains, wallthresh, varnames) wallinfo = makeWallInfo(newoutedges, newwalldomains, newvarsaffectedatwall) wallinfo = pp.truncateExtendedWallGraph(booleanoutedges, newoutedges, wallinfo) patternnames, patternmaxmin, originalpatterns = fp.parsePatterns() patterns = pp.translatePatterns(varnames, patternnames, patternmaxmin, cyclic=1) solutions = [[(0, 5, 8, 9, 3, 1, 0), (0, 6, 11, 13, 16, 9, 3, 1, 0), (0, 6, 12, 14, 8, 9, 3, 1, 0), (0, 6, 12, 15, 16, 9, 3, 1, 0)], [(4, 7, 13, 16, 9, 3, 1, 0, 4)], [(10, 7, 13, 16, 10)], None, [(2, 7, 13, 16, 9, 3, 2)], None] patterns = [p for pat in patterns for p in pat] for p, s in zip(patterns, solutions): match = matchPattern(p, wallinfo, cyclic=1, findallmatches=findallmatches) if s: if showme and findallmatches: print set(match) == set(s) if showme and not findallmatches: print match[0] in s else: if showme: print 'None' in match and 'Pattern' in match
def test0(): outedges,walldomains,varsaffectedatwall=tc.test0() wallinfo = wl.makeWallInfo(outedges,walldomains,varsaffectedatwall) print wallinfo[(3,4)]==[(6,('um',))] print wallinfo[(1,4)]==[(6,('um',))] print wallinfo[(2,0)]==[(1,('md',))] print set(wallinfo[(6,5)])==set([(2,('dM',)),(3,('dM',))])
def test0(): outedges, walldomains, varsaffectedatwall = tc.test0() wallinfo = wl.makeWallInfo(outedges, walldomains, varsaffectedatwall) print wallinfo[(3, 4)] == [(6, ('um', ))] print wallinfo[(1, 4)] == [(6, ('um', ))] print wallinfo[(2, 0)] == [(1, ('md', ))] print set(wallinfo[(6, 5)]) == set([(2, ('dM', )), (3, ('dM', ))])
def test2(showme=1, findallmatches=1): wallinfo = makeWallInfo(*tc.test2()) pattern = ['dM', 'md', 'um', 'Mu', 'dM'] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(2, 0, 1, 3, 2), (2, 0, 1, 4, 6, 5, 2)]) if showme and not findallmatches: print match[0] in [(2, 0, 1, 3, 2), (2, 0, 1, 4, 6, 5, 2)] pattern = ['Mu', 'dM', 'md', 'um', 'Mu'] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(3, 2, 0, 1, 3), (6, 5, 2, 0, 1, 4, 6)]) if showme and not findallmatches: print match[0] in [(3, 2, 0, 1, 3), (6, 5, 2, 0, 1, 4, 6)] pattern = ['um', 'Mu'] #acyclic match = matchPattern(pattern, wallinfo, cyclic=0, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(1, 4, 6), (1, 3)]) if showme and not findallmatches: print match[0] in [(1, 4, 6), (1, 3)]
def testtiming(iterates=5000): outedges, walldomains, varsaffectedatwall, varnames, threshnames = tc.test6() wallinfo = makeWallInfo(outedges, walldomains, varsaffectedatwall) patternnames, patternmaxmin = fp.parsePatterns() patterns = pp.translatePatterns(varnames, patternnames, patternmaxmin, cyclic=1) for _ in range(iterates): for p in patterns: match = matchPattern(p, wallinfo, cyclic=1, findallmatches=1)
def testtiming(iterates=5000): outedges,walldomains,varsaffectedatwall,varnames,threshnames=tc.test6() wallinfo = makeWallInfo(outedges,walldomains,varsaffectedatwall) patternnames,patternmaxmin=fp.parsePatterns() patterns=pp.translatePatterns(varnames,patternnames,patternmaxmin,cyclic=1) for _ in range(iterates): for p in patterns: match = matchPattern(p,wallinfo,cyclic=1,findallmatches=1)
def test6(): domaingraph,domaincells,morseset,vertexmap,outedges,walldomains,varsaffectedatwall,varnames,threshnames=tc.test6() extendedmorsegraph,extendedmorsecells=pp.makeExtendedMorseSetDomainGraph(vertexmap,morseset,domaingraph,domaincells) print extendedmorsegraph==[[12,3],[0,4],[11,1,12],[4,5,7],[8],[12,6],[2,4],[8,9],[10],[5,10],[6],[],[]] newoutedges,wallthresh,newwalldomains,booleanoutedges=pp.makeWallGraphFromDomainGraph(len(vertexmap),extendedmorsegraph, extendedmorsecells) print newwalldomains==[ (1.5,0.5,1), (2,0.5,0.5), (1.5,1,0.5), (2,1.5,0.5), (1,1.5,1.5), (1.5,1.5,1), (1.5,1,1.5), (2.5,1,0.5), (2.5,0.5,1), (3,0.5,0.5), (3,1.5,0.5), (2,0.5,1.5), (2.5,1,1.5), (2,1.5,1.5), (2.5,1.5,1), (3.5,1,0.5), (3.5,0.5,1), (3.5,1.5,1), (3,0.5,1.5), (3.5,1,1.5), (3,1.5,1.5) ] print newoutedges==[(),(7,8,9),(0,1),(10,),(),(2,3),(),(10,),(11,12),(15,16),(17,),(),(13,14),(4,5,6),(10,),(17,),(18,19),(20,),(11,12),(20,),(13,14)] newvarsaffectedatwall=pp.varsAtWalls(threshnames,newwalldomains,wallthresh,varnames) print newvarsaffectedatwall==[0,1,2,1,0,0,2,2,0,2,2,1,2,1,0,2,0,0,2,2,2] wallinfo = wl.makeWallInfo(newoutedges,newwalldomains,newvarsaffectedatwall) wallinfo = pp.truncateExtendedWallGraph(booleanoutedges,newoutedges,wallinfo) print set(wallinfo.keys())==set([(0,4),(0,5),(0,6),(1,0),(2,7),(3,1),(3,2),(4,7),(5,8),(6,11),(6,12),(7,13),(8,9),(8,10),(9,3),(10,7),(11,13),(12,14),(12,15),(13,16),(14,8),(15,16),(16,9),(16,10)]) print set(wallinfo[(1,0)])==set( [ (4,('umu',)), (5,('umu',)), (6,('umu',))] ) print wallinfo[(0,4)]==[(7,('uuM',))] print wallinfo[(0,5)]==[(8,('Muu',))] print set(wallinfo[(0,6)])==set([(11,('uuu',)),(12,('uuu',))]) print wallinfo[(2,7)]==[(13,('uum',))] print wallinfo[(3,1)]==[(0,('udm',))] print wallinfo[(3,2)]==[(7,('umd',))] print wallinfo[(4,7)]==[(13,('uum',))] print set(wallinfo[(5,8)])==set([(9,('duM',)),(10,('duM',))]) print wallinfo[(6,11)]==[(13,('uuu',))] print set(wallinfo[(6,12)])==set([(14,('Muu',)),(15,('Muu',))]) print wallinfo[(7,13)]==[(16,('Muu',))] print wallinfo[(8,9)]==[(3,('dMd',))] print wallinfo[(8,10)]==[(7,('mud',))] print set(wallinfo[(9,3)])==set([(1,('mdd',)),(2,('mdd',))]) print wallinfo[(10,7)]==[(13,('uum',))] print wallinfo[(11,13)]==[(16,('Muu',))] print wallinfo[(12,14)]==[(8,('duu',))] print wallinfo[(12,15)]==[(16,('duu',))] print set(wallinfo[(13,16)])==set([(9,('duM',)),(10,('duM',))]) print set(wallinfo[(14,8)])==set([(9,('duM',)),(10,('duM',))]) print set(wallinfo[(15,16)])==set([(9,('duM',)),(10,('duM',))]) print wallinfo[(16,9)]==[(3,('dMd',))] print wallinfo[(16,10)]==[(7,('mud',))]
def test3(): domaingraph,domaincells,morseset,vertexmap,outedges,walldomains,varsaffectedatwall,varnames,threshnames=tc.test3() extendedmorsegraph,extendedmorsecells=pp.makeExtendedMorseSetDomainGraph(vertexmap,morseset,domaingraph,domaincells) newoutedges,wallthresh,newwalldomains,booleanoutedges=pp.makeWallGraphFromDomainGraph(len(vertexmap),extendedmorsegraph, extendedmorsecells) newvarsaffectedatwall=pp.varsAtWalls(threshnames,newwalldomains,wallthresh,varnames) wallinfo = wl.makeWallInfo(newoutedges,newwalldomains,newvarsaffectedatwall) wallinfo = pp.truncateExtendedWallGraph(booleanoutedges,newoutedges,wallinfo) print set(wallinfo.keys())==set([(0,1),(1,2),(2,3),(3,4),(4,5),(5,0)]) print wallinfo[(0,1)]==[(2,('dmu',))] print wallinfo[(1,2)]==[(3,('duM',))] print wallinfo[(2,3)]==[(4,('mud',))] print wallinfo[(3,4)]==[(5,('uMd',))] print wallinfo[(4,5)]==[(0,('udm',))] print wallinfo[(5,0)]==[(1,('Mdu',))]
def test1(showme=1, findallmatches=1): wallinfo = makeWallInfo(*tc.test1()) pattern = ["md", "um", "Mu", "dM", "md"] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme: print match == [(0, 1, 3, 2, 0)] pattern = ["md", "um", "Mu", "dM", "Md"] # 'Md' DNE in graph match = matchPattern(pattern, wallinfo, cyclic=0, findallmatches=findallmatches) if showme: print "None" in match pattern = ["md", "Mu", "dM", "md"] # intermediate extrema match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme: print "None" in match
def preprocess(fname1='dsgrn_output.json',fname2='dsgrn_domaingraph.json',fname3='dsgrn_domaincells.json',pname='patterns.txt',cyclic=1): # read input files varnames,threshnames,morsedomgraph,morsecells,vertexmap=fp.parseMorseSet(fname1) domaingraph=fp.parseDomainGraph(fname2) domaincells=fp.parseDomainCells(fname3) patternnames,patternmaxmin,originalpatterns=fp.parsePatterns(pname) # put max/min patterns in terms of the alphabet u,m,M,d patterns=translatePatterns(varnames,patternnames,patternmaxmin,cyclic=cyclic) # translate domain graph into wall graph extendedmorsegraph,extendedmorsecells=makeExtendedMorseSetDomainGraph(vertexmap,morsecells,domaingraph,domaincells) outedges,wallthresh,walldomains,booleanoutedges=makeWallGraphFromDomainGraph(len(vertexmap),extendedmorsegraph, extendedmorsecells) # record which variable is affected at each wall varsaffectedatwall=varsAtWalls(threshnames,walldomains,wallthresh,varnames) # make wall labels wallinfo = wl.makeWallInfo(outedges,walldomains,varsaffectedatwall) # truncate back to Morse wall graph wallinfo = truncateExtendedWallGraph(booleanoutedges,outedges,wallinfo) return patterns, originalpatterns, wallinfo
def preprocess(morseset_jsonstr,domgraph_jsonstr,domaincells_jsonstr,patternstr,cyclic=1): # read json strings varnames,threshnames,morsedomgraph,morsecells,vertexmap,domaingraph,domaincells=extractFromJSON(morseset_jsonstr,domgraph_jsonstr,domaincells_jsonstr) # read pattern string patternnames,patternmaxmin,originalpatterns=parsePatternString(patternstr) # put max/min patterns in terms of the alphabet u,m,M,d patterns=translatePatterns(varnames,patternnames,patternmaxmin,cyclic=cyclic) # translate domain graph into extended wall graph extendedmorsegraph,extendedmorsecells=reindexDomainGraph(vertexmap,morsecells,domaingraph,domaincells) outedges,wallthresh,walldomains,booleanoutedges=makeWallGraphFromDomainGraph(len(vertexmap),extendedmorsegraph, extendedmorsecells) # record which variable is affected at each wall varsaffectedatwall=varsAtWalls(threshnames,walldomains,wallthresh,varnames) # make wall labels with extended wall graph wallinfo = wl.makeWallInfo(outedges,walldomains,varsaffectedatwall) # REQUIRED: truncate back to Morse wall graph so that the pattern search is only over the morse set # However, reindexing may not be necessary wallinfo = truncateExtendedWallGraph(booleanoutedges,outedges,wallinfo) return patterns, originalpatterns, wallinfo
def test0(showme=1, findallmatches=1): wallinfo = makeWallInfo(*tc.test0()) pattern = ['md', 'um', 'Mu', 'dM', 'md'] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(0, 1, 4, 6, 5, 2, 0), (3, 4, 6, 5, 3)]) if showme and not findallmatches: print match[0] in [(0, 1, 4, 6, 5, 2, 0), (3, 4, 6, 5, 3)] pattern = ['md', 'um', 'Mu', 'dM', 'md', 'um', 'Mu', 'dM', 'md'] #check double loop match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(0, 1, 4, 6, 5, 2, 0, 1, 4, 6, 5, 2, 0), (3, 4, 6, 5, 3, 4, 6, 5, 3), (0, 1, 4, 6, 5, 3, 4, 6, 5, 2, 0), (3, 4, 6, 5, 2, 0, 1, 4, 6, 5, 3)]) if showme and not findallmatches: print match[0] in [(0, 1, 4, 6, 5, 2, 0, 1, 4, 6, 5, 2, 0), (3, 4, 6, 5, 3, 4, 6, 5, 3), (0, 1, 4, 6, 5, 3, 4, 6, 5, 2, 0), (3, 4, 6, 5, 2, 0, 1, 4, 6, 5, 3)] pattern = ['um', 'md'] #intermediate extrema match = matchPattern(pattern, wallinfo, cyclic=0, findallmatches=findallmatches) if showme: print 'None' in match pattern = ['ud', 'um', 'Mu'] # acyclic match = matchPattern(pattern, wallinfo, cyclic=0, findallmatches=findallmatches) if showme: print match == [(1, 4, 6)]
def test3(showme=1, findallmatches=1): domaingraph, domaincells, morseset, vertexmap, outedges, walldomains, varsaffectedatwall, varnames, threshnames = ( tc.test3() ) extendedmorsegraph, extendedmorsecells = pp.makeExtendedMorseSetDomainGraph( vertexmap, morseset, domaingraph, domaincells ) newoutedges, wallthresh, newwalldomains, booleanoutedges = pp.makeWallGraphFromDomainGraph( len(vertexmap), extendedmorsegraph, extendedmorsecells ) newvarsaffectedatwall = pp.varsAtWalls(threshnames, newwalldomains, wallthresh, varnames) wallinfo = makeWallInfo(newoutedges, newwalldomains, newvarsaffectedatwall) wallinfo = pp.truncateExtendedWallGraph(booleanoutedges, newoutedges, wallinfo) patternnames, patternmaxmin, originalpatterns = fp.parsePatterns() patterns = pp.translatePatterns(varnames, patternnames, patternmaxmin, cyclic=1) match = matchPattern(patterns[0][0], wallinfo, cyclic=1, findallmatches=findallmatches) if showme: print match == [(5, 0, 1, 2, 3, 4, 5)] match = matchPattern(patterns[1][0], wallinfo, cyclic=1, findallmatches=findallmatches) if showme: print "None" in match
def test3(): domaingraph, domaincells, morseset, vertexmap, outedges, walldomains, varsaffectedatwall, varnames, threshnames = tc.test3( ) extendedmorsegraph, extendedmorsecells = pp.makeExtendedMorseSetDomainGraph( vertexmap, morseset, domaingraph, domaincells) newoutedges, wallthresh, newwalldomains, booleanoutedges = pp.makeWallGraphFromDomainGraph( len(vertexmap), extendedmorsegraph, extendedmorsecells) newvarsaffectedatwall = pp.varsAtWalls(threshnames, newwalldomains, wallthresh, varnames) wallinfo = wl.makeWallInfo(newoutedges, newwalldomains, newvarsaffectedatwall) wallinfo = pp.truncateExtendedWallGraph(booleanoutedges, newoutedges, wallinfo) print set(wallinfo.keys()) == set([(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 0)]) print wallinfo[(0, 1)] == [(2, ('dmu', ))] print wallinfo[(1, 2)] == [(3, ('duM', ))] print wallinfo[(2, 3)] == [(4, ('mud', ))] print wallinfo[(3, 4)] == [(5, ('uMd', ))] print wallinfo[(4, 5)] == [(0, ('udm', ))] print wallinfo[(5, 0)] == [(1, ('Mdu', ))]
def test6(showme=1, findallmatches=1): domaingraph, domaincells, morseset, vertexmap, outedges, walldomains, varsaffectedatwall, varnames, threshnames = ( tc.test6() ) extendedmorsegraph, extendedmorsecells = pp.makeExtendedMorseSetDomainGraph( vertexmap, morseset, domaingraph, domaincells ) newoutedges, wallthresh, newwalldomains, booleanoutedges = pp.makeWallGraphFromDomainGraph( len(vertexmap), extendedmorsegraph, extendedmorsecells ) newvarsaffectedatwall = pp.varsAtWalls(threshnames, newwalldomains, wallthresh, varnames) wallinfo = makeWallInfo(newoutedges, newwalldomains, newvarsaffectedatwall) wallinfo = pp.truncateExtendedWallGraph(booleanoutedges, newoutedges, wallinfo) patternnames, patternmaxmin, originalpatterns = fp.parsePatterns() patterns = pp.translatePatterns(varnames, patternnames, patternmaxmin, cyclic=1) solutions = [ [ (0, 5, 8, 9, 3, 1, 0), (0, 6, 11, 13, 16, 9, 3, 1, 0), (0, 6, 12, 14, 8, 9, 3, 1, 0), (0, 6, 12, 15, 16, 9, 3, 1, 0), ], [(4, 7, 13, 16, 9, 3, 1, 0, 4)], [(10, 7, 13, 16, 10)], None, [(2, 7, 13, 16, 9, 3, 2)], None, ] patterns = [p for pat in patterns for p in pat] for p, s in zip(patterns, solutions): match = matchPattern(p, wallinfo, cyclic=1, findallmatches=findallmatches) if s: if showme and findallmatches: print set(match) == set(s) if showme and not findallmatches: print match[0] in s else: if showme: print "None" in match and "Pattern" in match
def test0(showme=1, findallmatches=1): wallinfo = makeWallInfo(*tc.test0()) pattern = ["md", "um", "Mu", "dM", "md"] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(0, 1, 4, 6, 5, 2, 0), (3, 4, 6, 5, 3)]) if showme and not findallmatches: print match[0] in [(0, 1, 4, 6, 5, 2, 0), (3, 4, 6, 5, 3)] pattern = ["md", "um", "Mu", "dM", "md", "um", "Mu", "dM", "md"] # check double loop match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set( [ (0, 1, 4, 6, 5, 2, 0, 1, 4, 6, 5, 2, 0), (3, 4, 6, 5, 3, 4, 6, 5, 3), (0, 1, 4, 6, 5, 3, 4, 6, 5, 2, 0), (3, 4, 6, 5, 2, 0, 1, 4, 6, 5, 3), ] ) if showme and not findallmatches: print match[0] in [ (0, 1, 4, 6, 5, 2, 0, 1, 4, 6, 5, 2, 0), (3, 4, 6, 5, 3, 4, 6, 5, 3), (0, 1, 4, 6, 5, 3, 4, 6, 5, 2, 0), (3, 4, 6, 5, 2, 0, 1, 4, 6, 5, 3), ] pattern = ["um", "md"] # intermediate extrema match = matchPattern(pattern, wallinfo, cyclic=0, findallmatches=findallmatches) if showme: print "None" in match pattern = ["ud", "um", "Mu"] # acyclic match = matchPattern(pattern, wallinfo, cyclic=0, findallmatches=findallmatches) if showme: print match == [(1, 4, 6)]
def test2(showme=1, findallmatches=1): wallinfo = makeWallInfo(*tc.test2()) pattern = ["dM", "md", "um", "Mu", "dM"] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(2, 0, 1, 3, 2), (2, 0, 1, 4, 6, 5, 2)]) if showme and not findallmatches: print match[0] in [(2, 0, 1, 3, 2), (2, 0, 1, 4, 6, 5, 2)] pattern = ["Mu", "dM", "md", "um", "Mu"] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(3, 2, 0, 1, 3), (6, 5, 2, 0, 1, 4, 6)]) if showme and not findallmatches: print match[0] in [(3, 2, 0, 1, 3), (6, 5, 2, 0, 1, 4, 6)] pattern = ["um", "Mu"] # acyclic match = matchPattern(pattern, wallinfo, cyclic=0, findallmatches=findallmatches) if showme and findallmatches: print set(match) == set([(1, 4, 6), (1, 3)]) if showme and not findallmatches: print match[0] in [(1, 4, 6), (1, 3)]
def test1(showme=1, findallmatches=1): wallinfo = makeWallInfo(*tc.test1()) pattern = ['md', 'um', 'Mu', 'dM', 'md'] match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme: print match == [(0, 1, 3, 2, 0)] pattern = ['md', 'um', 'Mu', 'dM', 'Md'] # 'Md' DNE in graph match = matchPattern(pattern, wallinfo, cyclic=0, findallmatches=findallmatches) if showme: print 'None' in match pattern = ['md', 'Mu', 'dM', 'md'] # intermediate extrema match = matchPattern(pattern, wallinfo, cyclic=1, findallmatches=findallmatches) if showme: print 'None' in match
def test5(): domaingraph,domaincells,morseset,vertexmap,outedges,walldomains,varsaffectedatwall,varnames,threshnames=tc.test5() extendedmorsegraph,extendedmorsecells=pp.makeExtendedMorseSetDomainGraph(vertexmap,morseset,domaingraph,domaincells) newoutedges,wallthresh,newwalldomains,booleanoutedges=pp.makeWallGraphFromDomainGraph(len(vertexmap),extendedmorsegraph, extendedmorsecells) print newwalldomains==walldomains+[(0.5,2,0.5),(1,2.5,0.5),(0.5,2.5,1),(1.5,0.5,1),(1,0.5,1.5),(1.5,1,1.5),(1.5,1.5,1),(1,1.5,1.5),(1.5,2,1.5)] print newoutedges==outedges+[(1, 2), (5,), (9,), (3,), (6,), (17, 18, 19), (4,), (7, 8), (10,)] newvarsaffectedatwall=pp.varsAtWalls(threshnames,newwalldomains,wallthresh,varnames) print newvarsaffectedatwall[:11]==varsaffectedatwall wallinfo = wl.makeWallInfo(newoutedges,newwalldomains,newvarsaffectedatwall) wallinfo = pp.truncateExtendedWallGraph(booleanoutedges,newoutedges,wallinfo) print set(wallinfo.keys())==set([(0,3),(1,0),(2,4),(3,4),(4,5),(5,10),(6,0),(7,1),(7,2),(8,6),(9,7),(9,8),(10,9)]) print wallinfo[(0,3)]==[(4,('uud',))] print wallinfo[(1,0)]==[(3,('umd',))] print wallinfo[(2,4)]==[(5,('uum',))] print wallinfo[(3,4)]==[(5,('uum',))] print wallinfo[(4,5)]==[(10,('Muu',))] print wallinfo[(5,10)]==[(9,('dMu',))] print wallinfo[(6,0)]==[(3,('umd',))] print wallinfo[(7,1)]==[(0,('udd',))] print wallinfo[(7,2)]==[(4,('umd',))] print wallinfo[(8,6)]==[(0,('mdd',))] print set(wallinfo[(9,7)])==set([(1,('mdd',)),(2,('mdd',))]) print set(wallinfo[(10,9)])==set([(7,('ddM',)),(8,('ddM',))])
def test5(): domaingraph, domaincells, morseset, vertexmap, outedges, walldomains, varsaffectedatwall, varnames, threshnames = tc.test5( ) extendedmorsegraph, extendedmorsecells = pp.makeExtendedMorseSetDomainGraph( vertexmap, morseset, domaingraph, domaincells) newoutedges, wallthresh, newwalldomains, booleanoutedges = pp.makeWallGraphFromDomainGraph( len(vertexmap), extendedmorsegraph, extendedmorsecells) print newwalldomains == walldomains + [(0.5, 2, 0.5), (1, 2.5, 0.5), (0.5, 2.5, 1), (1.5, 0.5, 1), (1, 0.5, 1.5), (1.5, 1, 1.5), (1.5, 1.5, 1), (1, 1.5, 1.5), (1.5, 2, 1.5)] print newoutedges == outedges + [(1, 2), (5, ), (9, ), (3, ), (6, ), (17, 18, 19), (4, ), (7, 8), (10, )] newvarsaffectedatwall = pp.varsAtWalls(threshnames, newwalldomains, wallthresh, varnames) print newvarsaffectedatwall[:11] == varsaffectedatwall wallinfo = wl.makeWallInfo(newoutedges, newwalldomains, newvarsaffectedatwall) wallinfo = pp.truncateExtendedWallGraph(booleanoutedges, newoutedges, wallinfo) print set(wallinfo.keys()) == set([(0, 3), (1, 0), (2, 4), (3, 4), (4, 5), (5, 10), (6, 0), (7, 1), (7, 2), (8, 6), (9, 7), (9, 8), (10, 9)]) print wallinfo[(0, 3)] == [(4, ('uud', ))] print wallinfo[(1, 0)] == [(3, ('umd', ))] print wallinfo[(2, 4)] == [(5, ('uum', ))] print wallinfo[(3, 4)] == [(5, ('uum', ))] print wallinfo[(4, 5)] == [(10, ('Muu', ))] print wallinfo[(5, 10)] == [(9, ('dMu', ))] print wallinfo[(6, 0)] == [(3, ('umd', ))] print wallinfo[(7, 1)] == [(0, ('udd', ))] print wallinfo[(7, 2)] == [(4, ('umd', ))] print wallinfo[(8, 6)] == [(0, ('mdd', ))] print set(wallinfo[(9, 7)]) == set([(1, ('mdd', )), (2, ('mdd', ))]) print set(wallinfo[(10, 9)]) == set([(7, ('ddM', )), (8, ('ddM', ))])
def test6(): domaingraph, domaincells, morseset, vertexmap, outedges, walldomains, varsaffectedatwall, varnames, threshnames = tc.test6( ) extendedmorsegraph, extendedmorsecells = pp.makeExtendedMorseSetDomainGraph( vertexmap, morseset, domaingraph, domaincells) print extendedmorsegraph == [[12, 3], [0, 4], [11, 1, 12], [4, 5, 7], [8], [12, 6], [2, 4], [8, 9], [10], [5, 10], [6], [], []] newoutedges, wallthresh, newwalldomains, booleanoutedges = pp.makeWallGraphFromDomainGraph( len(vertexmap), extendedmorsegraph, extendedmorsecells) print newwalldomains == [(1.5, 0.5, 1), (2, 0.5, 0.5), (1.5, 1, 0.5), (2, 1.5, 0.5), (1, 1.5, 1.5), (1.5, 1.5, 1), (1.5, 1, 1.5), (2.5, 1, 0.5), (2.5, 0.5, 1), (3, 0.5, 0.5), (3, 1.5, 0.5), (2, 0.5, 1.5), (2.5, 1, 1.5), (2, 1.5, 1.5), (2.5, 1.5, 1), (3.5, 1, 0.5), (3.5, 0.5, 1), (3.5, 1.5, 1), (3, 0.5, 1.5), (3.5, 1, 1.5), (3, 1.5, 1.5)] print newoutedges == [(), (7, 8, 9), (0, 1), (10, ), (), (2, 3), (), (10, ), (11, 12), (15, 16), (17, ), (), (13, 14), (4, 5, 6), (10, ), (17, ), (18, 19), (20, ), (11, 12), (20, ), (13, 14)] newvarsaffectedatwall = pp.varsAtWalls(threshnames, newwalldomains, wallthresh, varnames) print newvarsaffectedatwall == [ 0, 1, 2, 1, 0, 0, 2, 2, 0, 2, 2, 1, 2, 1, 0, 2, 0, 0, 2, 2, 2 ] wallinfo = wl.makeWallInfo(newoutedges, newwalldomains, newvarsaffectedatwall) wallinfo = pp.truncateExtendedWallGraph(booleanoutedges, newoutedges, wallinfo) print set(wallinfo.keys()) == set([(0, 4), (0, 5), (0, 6), (1, 0), (2, 7), (3, 1), (3, 2), (4, 7), (5, 8), (6, 11), (6, 12), (7, 13), (8, 9), (8, 10), (9, 3), (10, 7), (11, 13), (12, 14), (12, 15), (13, 16), (14, 8), (15, 16), (16, 9), (16, 10)]) print set(wallinfo[(1, 0)]) == set([(4, ('umu', )), (5, ('umu', )), (6, ('umu', ))]) print wallinfo[(0, 4)] == [(7, ('uuM', ))] print wallinfo[(0, 5)] == [(8, ('Muu', ))] print set(wallinfo[(0, 6)]) == set([(11, ('uuu', )), (12, ('uuu', ))]) print wallinfo[(2, 7)] == [(13, ('uum', ))] print wallinfo[(3, 1)] == [(0, ('udm', ))] print wallinfo[(3, 2)] == [(7, ('umd', ))] print wallinfo[(4, 7)] == [(13, ('uum', ))] print set(wallinfo[(5, 8)]) == set([(9, ('duM', )), (10, ('duM', ))]) print wallinfo[(6, 11)] == [(13, ('uuu', ))] print set(wallinfo[(6, 12)]) == set([(14, ('Muu', )), (15, ('Muu', ))]) print wallinfo[(7, 13)] == [(16, ('Muu', ))] print wallinfo[(8, 9)] == [(3, ('dMd', ))] print wallinfo[(8, 10)] == [(7, ('mud', ))] print set(wallinfo[(9, 3)]) == set([(1, ('mdd', )), (2, ('mdd', ))]) print wallinfo[(10, 7)] == [(13, ('uum', ))] print wallinfo[(11, 13)] == [(16, ('Muu', ))] print wallinfo[(12, 14)] == [(8, ('duu', ))] print wallinfo[(12, 15)] == [(16, ('duu', ))] print set(wallinfo[(13, 16)]) == set([(9, ('duM', )), (10, ('duM', ))]) print set(wallinfo[(14, 8)]) == set([(9, ('duM', )), (10, ('duM', ))]) print set(wallinfo[(15, 16)]) == set([(9, ('duM', )), (10, ('duM', ))]) print wallinfo[(16, 9)] == [(3, ('dMd', ))] print wallinfo[(16, 10)] == [(7, ('mud', ))]