def rate_selection(selection, prog, v):

    javaFlag = True if v == 'v0' else False
    if javaFlag:
        faultMatrix = "input/{}_{}/fault_matrix.pickle".format(prog, v)
    else:
        faultMatrix = "input/{}_{}/fault_matrix_key_tc.pickle".format(prog, v)
    inputFile = "input/{}_{}/{}-bbox.txt".format(prog, v, prog)

    fdl = metric.fdl(selection, faultMatrix, False)
    tsr = metric.tsr(selection, inputFile)
    fft = metric.fft(selection, faultMatrix, False)
    apfd = metric.apfd(selection, faultMatrix, False)
    return (fdl, fft, apfd, tsr)
Example #2
0
def bboxPrioritization(name, prog, v, ctype, k, 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 == "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, bbox=True, k=k, memory=False)
                else:
                    stime, ptime, prioritization = fast.fast_(
                        fin, selsize, r=r, b=b, bbox=True, k=k, 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, bbox=True, k=k, memory=False)
                else:
                    stime, ptime, prioritization = fast.fast_pw(
                        fin, r, b, bbox=True, k=k, 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 == "STR":
        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.str_(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 == "I-TSD":
        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.i_tsd(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()
Example #3
0
def bboxPrioritization(name, prog, v, ctype, k, 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_FOLDER.format(prog, v, name, repeats)
    ppath = outpath + "prioritized/"

    timesMap = priorTime.getTimesMap("input/{}_{}/".format(prog, v))

    objective_function_values = []

    if ("{}-{}.tsv".format(name, ctype)) not in set(os.listdir(outpath)):
        ptimes, stimes, apfds, realDetectionTime, apfds_c = [], [], [], [], []
        for run in xrange(repeats):
            print " Run", run
            # SELECT APROACH
            memory = not javaFlag
            if name == "FAST-" + selsize.__name__[:-1]:
                stime, ptime, prioritization = fast.fast_(
                        fin, selsize, r, b, bbox=True, k=k, memory=memory)
            elif name == "FAST-pw":
                stime, ptime, prioritization = fast.fast_pw(
                        fin, r, b, bbox=True, k=k, memory=memory)
            elif name == "FAST-time":
                stime, ptime, prioritization, dissimilarity_value, time_value = fast.fast_time(
                        fin, r, b, "input/{}_{}/".format(prog, v), bbox=True, k=k, memory=memory)
            elif name == "TIME-FAST":
                stime, ptime, prioritization = fast.time_fast(
                        fin, r, b, "input/{}_{}/".format(prog, v), bbox=True, k=k, memory=memory)
            elif name == "I-TSD":
                stime, ptime, prioritization = competitors.i_tsd(fin)
            elif name == "STR":
                stime, ptime, prioritization = competitors.str_(fin)
            else:
                print("Wrong input.")
                print(usage)
                exit()

            writePrioritization(ppath, name, ctype, run, prioritization)
            apfd = metric.apfd(prioritization, fault_matrix, javaFlag)
            apfd_c = metric.apfd_c(prioritization, fault_matrix, timesMap)
            realDetectionTime = metric.getUsedTime(prioritization, fault_matrix, "input/{}_{}/".format(prog, v))
            apfds.append(apfd)
            apfds_c.append(apfd_c)
            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

            # Only for multi-objetive
            if name == "FAST-time":
                objective_function_values.append((dissimilarity_value, time_value, apfd_c))

        rep = (name, stimes, ptimes, apfds, apfds_c, realDetectionTime)
        #writeOutput(outpath, ctype, rep, javaFlag)
        writeOutputWithTestTime(outpath, ctype, rep, javaFlag)
        print("")

        # Save all solutions
        outpath = OUTPUT_FOLDER.format(prog, v, name, repeats)
        fileout = "{}/{}-{}.tsv".format(outpath, name, 'results')
        with open(fileout, "w") as fout:

            # Only for multi-objetive
            if name == "FAST-time":
                solutions = []
                fout.write("Index\tDissimilarity\tTime\tAPFD_c\n")
                for idx, (dissimilarity_value, time_value, apfd_c) in enumerate(objective_function_values):
                    fout.write("{}\t{}\t{}\t{}\n".format(
                        idx, dissimilarity_value, time_value,  sum(apfd_c)/len(apfd_c)))
                    solutions.append(
                        [idx, dissimilarity_value, time_value,  sum(apfd_c)/len(apfd_c)])
                # Generate and save pareto frontier and graphic
                get_pareto_frontier_and_plot(solutions, outpath)
            
            # Others algorithms
            else: 
                fout.write("Index\tAPFD_c\n")
                for idx, apfd_c in enumerate(apfds_c):
                    fout.write("{}\t{}\n".format( idx, sum(apfd_c)/len(apfd_c)))
    else:
        print name, "already run."
Example #4
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_FOLDER .format(prog, v, name, repeats)
    ppath = outpath + "prioritized/"

    if name == "GT":
        if ("{}-{}.tsv".format(name, ctype)) not in set(os.listdir(outpath)):
            ptimes, stimes, apfds = [], [], []
            for run in xrange(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 xrange(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 xrange(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 xrange(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 xrange(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 xrange(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 xrange(repeats):
                print " Run", run
                stime, ptime, prioritization = competitors.art_f(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()