コード例 #1
0
ファイル: test_patternmatch.py プロジェクト: kmok002/DSGRN
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
コード例 #2
0
ファイル: test_patternmatch.py プロジェクト: kmok002/DSGRN
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)]
コード例 #3
0
ファイル: test_patternmatch.py プロジェクト: kmok002/DSGRN
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
コード例 #4
0
ファイル: test_patternmatch.py プロジェクト: kspendlove/DSGRN
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
コード例 #5
0
ファイル: test_timing.py プロジェクト: kmok002/DSGRN
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)
コード例 #6
0
ファイル: test_timing.py プロジェクト: kspendlove/DSGRN
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)
コード例 #7
0
ファイル: test_patternmatch.py プロジェクト: kmok002/DSGRN
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)]
コード例 #8
0
ファイル: test_patternmatch.py プロジェクト: kspendlove/DSGRN
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
コード例 #9
0
ファイル: test_patternmatch.py プロジェクト: kspendlove/DSGRN
def test7(showme=1, findallmatches=1):
    tc.test7()
    patterns, originalpatterns, wallinfo = pp.preprocess(cyclic=1)
    solutions = [None, None, [(1, 2, 3, 4, 5, 0, 1)], [(4, 5, 0, 1, 2, 3, 4)]]
    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:
                print match == s
        else:
            if showme:
                print "None" in match and "Pattern" in match
コード例 #10
0
ファイル: test_patternmatch.py プロジェクト: kspendlove/DSGRN
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)]
コード例 #11
0
ファイル: test_patternmatch.py プロジェクト: kspendlove/DSGRN
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)]
コード例 #12
0
ファイル: test_patternmatch.py プロジェクト: kmok002/DSGRN
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
コード例 #13
0
ファイル: test_patternmatch.py プロジェクト: kmok002/DSGRN
def test7(showme=1, findallmatches=1):
    tc.test7()
    patterns, originalpatterns, wallinfo = pp.preprocess(cyclic=1)
    solutions = [None, None, [(1, 2, 3, 4, 5, 0, 1)], [(4, 5, 0, 1, 2, 3, 4)]]
    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: print match == s
        else:
            if showme: print 'None' in match and 'Pattern' in match
コード例 #14
0
ファイル: test_patternmatch.py プロジェクト: kspendlove/DSGRN
def test8(showme=1, findallmatches=1):
    tc.test8()
    patterns, originalpatterns, wallinfo = pp.preprocess(cyclic=1)
    solutions = [[(1, 2, 6, 0, 1), (1, 3, 4, 5, 6, 0, 1)]] * 4 + [None] * 4
    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
コード例 #15
0
ファイル: test_patternmatch.py プロジェクト: kmok002/DSGRN
def test8(showme=1, findallmatches=1):
    tc.test8()
    patterns, originalpatterns, wallinfo = pp.preprocess(cyclic=1)
    solutions = [[(1, 2, 6, 0, 1), (1, 3, 4, 5, 6, 0, 1)]] * 4 + [None] * 4
    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
コード例 #16
0
ファイル: test_patternmatch.py プロジェクト: kspendlove/DSGRN
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