Пример #1
0
def wboxPrioritization(name, prog, v, ctype, n, r, b, repeats, selsize):
    javaFlag = True if v == "v0" else False

    fin = "input/{}_{}/{}-{}.txt".format(prog, v, prog, ctype)
    if javaFlag:
        fault_matrix = "input/{}_{}/fault_matrix.pickle".format(prog, v)
    else:
        fault_matrix = "input/{}_{}/fault_matrix_key_tc.pickle".format(prog, v)

    outpath = "output/{}_{}/".format(prog, v)
    ppath = outpath + "prioritized/"

    if name == "GT":
        if ("{}-{}.tsv".format(name, ctype)) not in set(os.listdir(outpath)):
            ptimes, stimes, apfds = [], [], []
            for run in range(repeats):
                print(" Run", run)
                stime, ptime, prioritization = competitors.gt(fin)
                writePrioritization(ppath, name, ctype, run, prioritization)
                apfd = metric.apfd(prioritization, fault_matrix, javaFlag)
                apfds.append(apfd)
                stimes.append(stime)
                ptimes.append(ptime)
                print("  Progress: 100%  ")
                print("  Running time:", stime + ptime)
                if javaFlag:
                    print("  APFD:", sum(apfds[run]) / len(apfds[run]))
                else:
                    print("  APFD:", apfd)
            rep = (name, stimes, ptimes, apfds)
            writeOutput(outpath, ctype, rep, javaFlag)
            print("")
        else:
            print(name, "already run.")

    elif name == "FAST-" + selsize.__name__[:-1]:
        if ("{}-{}.tsv".format(name, ctype)) not in set(os.listdir(outpath)):
            ptimes, stimes, apfds = [], [], []
            for run in range(repeats):
                print(" Run", run)
                if javaFlag:
                    stime, ptime, prioritization = fast.fast_(
                        fin, selsize, r=r, b=b, memory=False)
                else:
                    stime, ptime, prioritization = fast.fast_(
                        fin, selsize, r=r, b=b, memory=True)
                writePrioritization(ppath, name, ctype, run, prioritization)
                apfd = metric.apfd(prioritization, fault_matrix, javaFlag)
                apfds.append(apfd)
                stimes.append(stime)
                ptimes.append(ptime)
                print("  Progress: 100%  ")
                print("  Running time:", stime + ptime)
                if javaFlag:
                    print("  APFD:", sum(apfds[run]) / len(apfds[run]))
                else:
                    print("  APFD:", apfd)
            rep = (name, stimes, ptimes, apfds)
            writeOutput(outpath, ctype, rep, javaFlag)
            print("")
        else:
            print(name, "already run.")

    elif name == "FAST-pw":
        if ("{}-{}.tsv".format(name, ctype)) not in set(os.listdir(outpath)):
            ptimes, stimes, apfds = [], [], []
            for run in range(repeats):
                print(" Run", run)
                if javaFlag:
                    stime, ptime, prioritization = fast.fast_pw(fin, r, b)
                else:
                    stime, ptime, prioritization = fast.fast_pw(
                        fin, r, b, memory=True)
                writePrioritization(ppath, name, ctype, run, prioritization)
                apfd = metric.apfd(prioritization, fault_matrix, javaFlag)
                apfds.append(apfd)
                stimes.append(stime)
                ptimes.append(ptime)
                print("  Progress: 100%  ")
                print("  Running time:", stime + ptime)
                if javaFlag:
                    print("  APFD:", sum(apfds[run]) / len(apfds[run]))
                else:
                    print("  APFD:", apfd)
            rep = (name, stimes, ptimes, apfds)
            writeOutput(outpath, ctype, rep, javaFlag)
            print("")
        else:
            print(name, "already run.")

    elif name == "GA":
        if ("{}-{}.tsv".format(name, ctype)) not in set(os.listdir(outpath)):
            ptimes, stimes, apfds = [], [], []
            for run in range(repeats):
                print(" Run", run)
                stime, ptime, prioritization = competitors.ga(fin)
                writePrioritization(ppath, name, ctype, run, prioritization)
                apfd = metric.apfd(prioritization, fault_matrix, javaFlag)
                apfds.append(apfd)
                stimes.append(stime)
                ptimes.append(ptime)
                print("  Progress: 100%  ")
                print("  Running time:", stime + ptime)
                if javaFlag:
                    print("  APFD:", sum(apfds[run]) / len(apfds[run]))
                else:
                    print("  APFD:", apfd)
            rep = (name, stimes, ptimes, apfds)
            writeOutput(outpath, ctype, rep, javaFlag)
            print("")
        else:
            print(name, "already run.")

    elif name == "GA-S":
        if ("{}-{}.tsv".format(name, ctype)) not in set(os.listdir(outpath)):
            ptimes, stimes, apfds = [], [], []
            for run in range(repeats):
                print(" Run", run)
                stime, ptime, prioritization = competitors.ga_s(fin)
                writePrioritization(ppath, name, ctype, run, prioritization)
                apfd = metric.apfd(prioritization, fault_matrix, javaFlag)
                apfds.append(apfd)
                stimes.append(stime)
                ptimes.append(ptime)
                print("  Progress: 100%  ")
                print("  Running time:", stime + ptime)
                if javaFlag:
                    print("  APFD:", sum(apfds[run]) / len(apfds[run]))
                else:
                    print("  APFD:", apfd)
            rep = (name, stimes, ptimes, apfds)
            writeOutput(outpath, ctype, rep, javaFlag)
            print("")
        else:
            print(name, "already run.")

    elif name == "ART-D":
        if ("{}-{}.tsv".format(name, ctype)) not in set(os.listdir(outpath)):
            ptimes, stimes, apfds = [], [], []
            for run in range(repeats):
                print(" Run", run)
                stime, ptime, prioritization = competitors.artd(fin)
                writePrioritization(ppath, name, ctype, run, prioritization)
                apfd = metric.apfd(prioritization, fault_matrix, javaFlag)
                apfds.append(apfd)
                stimes.append(stime)
                ptimes.append(ptime)
                print("  Progress: 100%  ")
                print("  Running time:", stime + ptime)
                if javaFlag:
                    print("  APFD:", sum(apfds[run]) / len(apfds[run]))
                else:
                    print("  APFD:", apfd)
            rep = (name, stimes, ptimes, apfds)
            writeOutput(outpath, ctype, rep, javaFlag)
            print("")
        else:
            print(name, "already run.")

    elif name == "ART-F":
        if ("{}-{}.tsv".format(name, ctype)) not in set(os.listdir(outpath)):
            ptimes, stimes, apfds = [], [], []
            for run in range(repeats):
                print(" Run", run)
                stime, ptime, prioritization = competitors.artf(fin)
                writePrioritization(ppath, name, ctype, run, prioritization)
                apfd = metric.apfd(prioritization, fault_matrix, javaFlag)
                apfds.append(apfd)
                stimes.append(stime)
                ptimes.append(ptime)
                print("  Progress: 100%  ")
                print("  Running time:", stime + ptime)
                if javaFlag:
                    print("  APFD:", sum(apfds[run]) / len(apfds[run]))
                else:
                    print("  APFD:", apfd)
            rep = (name, stimes, ptimes, apfds)
            writeOutput(outpath, ctype, rep, javaFlag)
            print("")
        else:
            print(name, "already run.")

    else:
        print("Wrong input.")
        print(usage)
        exit()
Пример #2
0
def run_algorithm(script, covType, algorithm, prog, v, red):

    ## Removed since we are only running once with a large B
    ## Reduced from 50 for development efficiency
    ## Increase this number when generating data
    #repeats = 5
    print(f"running {algorithm} {covType}.....")
    # FAST-R parameters
    k, n, r, b = 5, 10, 1, 10
    dim = 10

    # FAST-f sample size
    def all_(x):
        return x

    def sqrt_(x):
        return int(math.sqrt(x)) + 1

    def log_(x):
        return int(math.log(x, 2)) + 1

    def one_(x):
        return 1

    inputFile = "input/{}_{}/{}-bbox.txt".format(prog, v, prog)
    wBoxFile = "input/{}_{}/{}-{}.txt".format(prog, v, prog, covType)
    numOfTCS = sum((1 for _ in open(inputFile)))
    selection = set()

    # Change this number to determine the fraction of the total tests we want
    reduction = float(red)

    B = int(numOfTCS * reduction)

    #if algorithm == "FAST++":
    #        pTime, rTime, sel = fastr.fastPlusPlus(inputFile, dim=dim, B=B)
    #        selection = sel

    #elif algorithm == "FAST-CS":
    #    for run in range(repeats):
    #        pTime, rTime, sel = fastr.fastCS(inputFile, dim=dim, B=B)
    #        selection = sel

    #elif algorithm == "FAST-pw":
    #    for run in range(repeats):
    #        pTime, rTime, sel = fastr.fast_pw(inputFile, dim=dim, B=B)
    #        selection = sel

    if algorithm == "GA":
        pTime, rTime, sel = competitors.ga(wBoxFile, B=B)
        selection = sel

    elif algorithm == "ART-D":
        pTime, rTime, sel = competitors.artd(wBoxFile, B=B)
        selection = sel

    elif algorithm == "ART-F":
        pTime, rTime, sel = competitors.artf(wBoxFile, B=B)
        selection = sel

    else:
        print('Not a supported algorithm: {}'.format(algorithm))
        exit()

    return selection
Пример #3
0
                                               run + 1)
            pickle.dump((pTime, rTime, fdl), open(tOut, "wb"))
            print("FAST-all", reduction, pTime, rTime, fdl)

        # WHITEBOX APPROACHES
        for run in range(repeats):
            pTime, rTime, sel = competitors.ga(wBoxFile, B=B)
            fdl = metric.fdl(sel, faultMatrix, javaFlag)
            sOut = "{}/{}-{}-{}.pickle".format(sPath, "GA", reduction, run + 1)
            pickle.dump(sel, open(sOut, "wb"))
            tOut = "{}/{}-{}-{}.pickle".format(tPath, "GA", reduction, run + 1)
            pickle.dump((pTime, rTime, fdl), open(tOut, "wb"))
            print("GA", reduction, pTime, rTime, fdl)

        for run in range(repeats):
            pTime, rTime, sel = competitors.artd(wBoxFile, B=B)
            fdl = metric.fdl(sel, faultMatrix, javaFlag)
            sOut = "{}/{}-{}-{}.pickle".format(sPath, "ART-D", reduction,
                                               run + 1)
            pickle.dump(sel, open(sOut, "wb"))
            tOut = "{}/{}-{}-{}.pickle".format(tPath, "ART-D", reduction,
                                               run + 1)
            pickle.dump((pTime, rTime, fdl), open(tOut, "wb"))
            print("ART-D", reduction, pTime, rTime, fdl)

        for run in range(repeats):
            pTime, rTime, sel = competitors.artf(wBoxFile, B=B)
            fdl = metric.fdl(sel, faultMatrix, javaFlag)
            sOut = "{}/{}-{}-{}.pickle".format(sPath, "ART-F", reduction,
                                               run + 1)
            pickle.dump(sel, open(sOut, "wb"))
Пример #4
0
def scalability(name, ts, tc, n, r, b, selsize):
    filename = "{}x{}".format(ts, tc)
    fin = "scalability/input/{}.txt".format(filename)
    outpath = "scalability/output/"


    if name == "FAST-" + selsize.__name__[:-1]:
        if ("{}-{}.tsv".format(name, filename)) not in set(os.listdir(outpath)):
            stime, ptime, prioritization = fast.fast_(
                fin, selsize, r=r, b=b, memory=False)
            print("  Progress: 100%  ")
            print("  Running time:", stime + ptime)
            rep = (name, stime, ptime)
            writeOutput(outpath, filename, rep)
        else:
            print(name, "already run.")

    elif name == "FAST-pw":
        if ("{}-{}.tsv".format(name, filename)) not in set(os.listdir(outpath)):
            stime, ptime, prioritization = fast.fast_pw(
                fin, r=r, b=b, memory=False)
            print("  Progress: 100%  ")
            print("  Running time:", stime + ptime)
            rep = (name, stime, ptime)
            writeOutput(outpath, filename, rep)
        else:
            print(name, "already run.")

    elif name == "STR":
        if ("{}-{}.tsv".format(name, filename)) not in set(os.listdir(outpath)):
            print(name)
            stime, ptime, prioritization = competitors.str_(fin)
            print("  Progress: 100%  ")
            print("  Running time:", stime + ptime)
            rep = (name, stime, ptime)
            writeOutput(outpath, filename, rep)
            print("")
        else:
            print(name, "already run.")

    elif name == "I-TSD":
        if ("{}-{}.tsv".format(name, filename)) not in set(os.listdir(outpath)):
            print(name)
            stime, ptime, prioritization = competitors.i_tsd(fin)
            print("  Progress: 100%  ")
            print("  Running time:", stime + ptime)
            rep = (name, stime, ptime)
            writeOutput(outpath, filename, rep)
            print("")
        else:
            print(name, "already run.")

    elif name == "GT":
        if ("{}-{}.tsv".format(name, filename)) not in set(os.listdir(outpath)):
            print(name)
            stime, ptime, prioritization = competitors.gt(fin)
            print("  Progress: 100%  ")
            print("  Running time:", stime + ptime)
            rep = (name, stime, ptime)
            writeOutput(outpath, filename, rep)
            print("")
        else:
            print(name, "already run.")

    elif name == "GA":
        if ("{}-{}.tsv".format(name, filename)) not in set(os.listdir(outpath)):
            print(name)
            stime, ptime, prioritization = competitors.ga(fin)
            print("  Progress: 100%  ")
            print("  Running time:", stime + ptime)
            rep = (name, stime, ptime)
            writeOutput(outpath, filename, rep)
            print("")
        else:
            print(name, "already run.")

    elif name == "GA-S":
        if ("{}-{}.tsv".format(name, filename)) not in set(os.listdir(outpath)):
            print(name)
            stime, ptime, prioritization = competitors.ga_s(fin)
            print("  Progress: 100%  ")
            print("  Running time:", stime + ptime)
            rep = (name, stime, ptime)
            writeOutput(outpath, filename, rep)
            print("")
        else:
            print(name, "already run.")

    elif name == "ART-D":
        if ("{}-{}.tsv".format(name, filename)) not in set(os.listdir(outpath)):
            print(name)
            stime, ptime, prioritization = competitors.artd(fin)
            print("  Progress: 100%  ")
            print("  Running time:", stime + ptime)
            rep = (name, stime, ptime)
            writeOutput(outpath, filename, rep)
            print("")
        else:
            print(name, "already run.")

    elif name == "ART-F":
        if ("{}-{}.tsv".format(name, filename)) not in set(os.listdir(outpath)):
            print(name)
            stime, ptime, prioritization = competitors.artf(fin)
            print("  Progress: 100%  ")
            print("  Running time:", stime + ptime)
            rep = (name, stime, ptime)
            writeOutput(outpath, filename, rep)
            print("")
        else:
            print(name, "already run.")

    else:
        print("Wrong input name.")