Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def test5():
    domaingraph, domaincells, morseset, vertexmap, outedges, walldomains, varsaffectedatwall, varnames, threshnames = tc.test5(
    )
    patternnames, patternmaxmin, originalpatterns = fp.parsePatterns()
    patterns = translatePatterns(varnames,
                                 patternnames,
                                 patternmaxmin,
                                 cyclic=1)
    print patterns == [[['mdd', 'umd', 'uum', 'Muu', 'dMu', 'ddM', 'mdd']],
                       [['mdd', 'umd', 'Mud', 'dum', 'dMu', 'ddM', 'mdd']]]
Exemplo n.º 6
0
def test3():
    domaingraph,domaincells,morseset,vertexmap,outedges,walldomains,varsaffectedatwall,varnames,threshnames=tc.test3()
    extendedmorsegraph,extendedmorsecells=pp.makeExtendedMorseSetDomainGraph(vertexmap,morseset,domaingraph,domaincells)
    print extendedmorsegraph==[[1,],[2,],[3,],[4,],[5,],[0,],[0,2,4],[1,3,5]]
    print extendedmorsecells==domaincells[1:-1]+[domaincells[0]]+[domaincells[-1]]
    newoutedges,wallthresh,newwalldomains,booleanoutedges=pp.makeWallGraphFromDomainGraph(len(vertexmap),extendedmorsegraph, extendedmorsecells)
    print newoutedges==outedges+[(0,),(2,),(4,),(1,),(3,),(5,)]
    print newwalldomains==walldomains+ [(1,0.5,0.5),(0.5,0.5,1),(0.5,1,0.5)] + [(1.5,1,1.5),(1,1.5,1.5),(1.5,1.5,1)]
    print wallthresh==[2,0,1,2,0,1,0,2,1,1,0,2]
    print pp.varsAtWalls(threshnames,newwalldomains,wallthresh,varnames)==varsaffectedatwall+[1,0,2,2,1,0]
    patternnames=[['X','Z','Y','X','Y','Z'],['Z','X','Y','Y','X','Z']]
    patternmaxmin=[['min','max','min','max','max','min'],['max','min','min','max','max','min']]
    patterns=translatePatterns(varnames,patternnames,patternmaxmin,cyclic=1)
    print patterns==[[['mdu','udM','umd','Mud','dMd','ddm','mdu']],[['ddM','mdd','umd','uMd','Mdd','ddm','ddM']]]
    patternnames,patternmaxmin,originalpatterns=fp.parsePatterns()
    print  translatePatterns(varnames,patternnames,patternmaxmin,cyclic=1)==[[['udm','Mdu','dmu','duM','mud','uMd','udm']],[['dum','muu','uMu','umu','uuM','Mud','dum']]]
Exemplo n.º 7
0
def test3():
    domaingraph, domaincells, morseset, vertexmap, outedges, walldomains, varsaffectedatwall, varnames, threshnames = tc.test3(
    )
    extendedmorsegraph, extendedmorsecells = pp.makeExtendedMorseSetDomainGraph(
        vertexmap, morseset, domaingraph, domaincells)
    print extendedmorsegraph == [[
        1,
    ], [
        2,
    ], [
        3,
    ], [
        4,
    ], [
        5,
    ], [
        0,
    ], [0, 2, 4], [1, 3, 5]]
    print extendedmorsecells == domaincells[1:-1] + [domaincells[0]
                                                     ] + [domaincells[-1]]
    newoutedges, wallthresh, newwalldomains, booleanoutedges = pp.makeWallGraphFromDomainGraph(
        len(vertexmap), extendedmorsegraph, extendedmorsecells)
    print newoutedges == outedges + [(0, ), (2, ), (4, ), (1, ), (3, ), (5, )]
    print newwalldomains == walldomains + [(1, 0.5, 0.5), (0.5, 0.5, 1),
                                           (0.5, 1, 0.5)] + [(1.5, 1, 1.5),
                                                             (1, 1.5, 1.5),
                                                             (1.5, 1.5, 1)]
    print wallthresh == [2, 0, 1, 2, 0, 1, 0, 2, 1, 1, 0, 2]
    print pp.varsAtWalls(threshnames, newwalldomains, wallthresh,
                         varnames) == varsaffectedatwall + [1, 0, 2, 2, 1, 0]
    patternnames = [['X', 'Z', 'Y', 'X', 'Y', 'Z'],
                    ['Z', 'X', 'Y', 'Y', 'X', 'Z']]
    patternmaxmin = [['min', 'max', 'min', 'max', 'max', 'min'],
                     ['max', 'min', 'min', 'max', 'max', 'min']]
    patterns = translatePatterns(varnames,
                                 patternnames,
                                 patternmaxmin,
                                 cyclic=1)
    print patterns == [[['mdu', 'udM', 'umd', 'Mud', 'dMd', 'ddm', 'mdu']],
                       [['ddM', 'mdd', 'umd', 'uMd', 'Mdd', 'ddm', 'ddM']]]
    patternnames, patternmaxmin, originalpatterns = fp.parsePatterns()
    print translatePatterns(
        varnames, patternnames, patternmaxmin,
        cyclic=1) == [[['udm', 'Mdu', 'dmu', 'duM', 'mud', 'uMd', 'udm']],
                      [['dum', 'muu', 'uMu', 'umu', 'uuM', 'Mud', 'dum']]]
Exemplo n.º 8
0
def test4():
    domaingraph,domaincells,morseset,vertexmap,outedges,walldomains,varsaffectedatwall,varnames,threshnames=tc.test4()
    extendedmorsegraph,extendedmorsecells=pp.makeExtendedMorseSetDomainGraph(vertexmap,morseset,domaingraph,domaincells)
    print extendedmorsegraph==[[6,1],[2,4],[5,],[0,],[3,],[4,],[]]
    print extendedmorsecells==domaincells[3:]+[domaincells[0]]
    newoutedges,wallthresh,newwalldomains,booleanoutedges=pp.makeWallGraphFromDomainGraph(len(vertexmap),extendedmorsegraph, extendedmorsecells)
    print newoutedges==[(),(2,3),(4,),(6,),(7,),(0,1),(5,),(6,)]
    print newwalldomains==[(1,2.5)] +walldomains
    print wallthresh==[0,1,1,0,0,0,1,1]
    print pp.varsAtWalls(threshnames,newwalldomains,wallthresh,varnames)==[0]+varsaffectedatwall
    patternnames=[['X1','X2','X1','X2'],['X1','X1','X2','X2']]
    patternmaxmin=[['min','min','max','max'],['max','min','min','max']]
    patterns=translatePatterns(varnames,patternnames,patternmaxmin,cyclic=1)
    print patterns==[[['md','um','Mu','dM','md']],[['Md','md','um','uM','Md']]]
    patternnames,patternmaxmin,originalpatterns=fp.parsePatterns()
    print patternnames==[['X2', 'X1', 'X2', 'X1'], ['X2', 'X2', 'X1', 'X1']]
    print patternmaxmin==[['max', 'min', 'min', 'max'], ['max', 'min', 'min', 'max']]
    print translatePatterns(varnames,patternnames,patternmaxmin,cyclic=1)==[[['dM','md','um','Mu','dM']],[['dM','dm','mu','Mu','dM']]]
Exemplo n.º 9
0
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
Exemplo n.º 10
0
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
Exemplo n.º 11
0
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
Exemplo n.º 12
0
def test4():
    domaingraph, domaincells, morseset, vertexmap, outedges, walldomains, varsaffectedatwall, varnames, threshnames = tc.test4(
    )
    extendedmorsegraph, extendedmorsecells = pp.makeExtendedMorseSetDomainGraph(
        vertexmap, morseset, domaingraph, domaincells)
    print extendedmorsegraph == [[6, 1], [2, 4], [
        5,
    ], [
        0,
    ], [
        3,
    ], [
        4,
    ], []]
    print extendedmorsecells == domaincells[3:] + [domaincells[0]]
    newoutedges, wallthresh, newwalldomains, booleanoutedges = pp.makeWallGraphFromDomainGraph(
        len(vertexmap), extendedmorsegraph, extendedmorsecells)
    print newoutedges == [(), (2, 3), (4, ), (6, ), (7, ), (0, 1), (5, ),
                          (6, )]
    print newwalldomains == [(1, 2.5)] + walldomains
    print wallthresh == [0, 1, 1, 0, 0, 0, 1, 1]
    print pp.varsAtWalls(threshnames, newwalldomains, wallthresh,
                         varnames) == [0] + varsaffectedatwall
    patternnames = [['X1', 'X2', 'X1', 'X2'], ['X1', 'X1', 'X2', 'X2']]
    patternmaxmin = [['min', 'min', 'max', 'max'],
                     ['max', 'min', 'min', 'max']]
    patterns = translatePatterns(varnames,
                                 patternnames,
                                 patternmaxmin,
                                 cyclic=1)
    print patterns == [[['md', 'um', 'Mu', 'dM', 'md']],
                       [['Md', 'md', 'um', 'uM', 'Md']]]
    patternnames, patternmaxmin, originalpatterns = fp.parsePatterns()
    print patternnames == [['X2', 'X1', 'X2', 'X1'], ['X2', 'X2', 'X1', 'X1']]
    print patternmaxmin == [['max', 'min', 'min', 'max'],
                            ['max', 'min', 'min', 'max']]
    print translatePatterns(varnames, patternnames, patternmaxmin,
                            cyclic=1) == [[['dM', 'md', 'um', 'Mu', 'dM']],
                                          [['dM', 'dm', 'mu', 'Mu', 'dM']]]
Exemplo n.º 13
0
def test6():
    domaingraph,domaincells,morseset,vertexmap,outedges,walldomains,varsaffectedatwall,varnames,threshnames=tc.test6()
    patternnames,patternmaxmin,originalpatterns=fp.parsePatterns()
    patterns=translatePatterns(varnames,patternnames,patternmaxmin,cyclic=1)
    print patterns==[[['umu','Muu','duM','dMd','mdd','udm','umu']],[['uuM','uum','Muu','duM','dMd','mdd','udm','umu','uuM']],[['mud','uum','Muu','duM','mud'],['mdd','udm','Mdu','ddM','mdd']],[['umd','uum','Muu','duM','dMd','mdd','umd']],[['dmd','dum','muu','uuM','uMd','Mdd','dmd']]]