Esempio n. 1
0
def main():
    if len(sys.argv) > 1:
        problem = loadProblem(sys.argv[1])
    else:
        problem = loadProblem(utils.getOpenFilename("problem.py"))

    # run all algorithms, gathering the traces and printing out the results as
    # we go
    algorithmList = [("Algorithm 3", algorithms.algorithm3),
                     ("Algorithm 4", algorithms.algorithm4),
                     ("Algorithm 5", algorithms.algorithm5)]

    steps = []

    for (name, function) in algorithmList:
        tracer = trace.TraceRecord()
        peak = function(problem, trace = tracer)
        steps.append(tracer.sequence)

        status = "is NOT a peak (INCORRECT!)"
        if problem.isPeak(peak):
            status = "is a peak"

        print(name + " : " + str(peak) + " => " + status)

    # write the trace out to a file
    with open("trace.jsonp", "w") as traceFile:
        traceFile.write("parse(")

        json.dump({
            "input" : problem.array,
            "steps" : steps
        }, traceFile)

        traceFile.write(")")
Esempio n. 2
0
def main():
    # if len(sys.argv) > 1:
    #     problem = loadProblem(sys.argv[1])
    # else:
    problem = loadProblem(utils.getOpenFilename("zeromatrix.py"))

    #  @TEST  zero matrix with one random 1

    # problem = [];
    # for i in range(10):
    #     resultRow = []

    #     for j in range(10):
    #         resultRow.append(0)

    #     result.append(resultRow)

    # problem[random.randint(0, 10)][random.randint(0, 10)] = 1

    # run all algorithms, gathering the traces and printing out the results as
    # we go
    algorithmList = [("Algorithm 1", algorithms.algorithm1),
                     ("Algorithm 2", algorithms.algorithm2),
                     ("Algorithm 3", algorithms.algorithm3),
                     ("Algorithm 4", algorithms.algorithm4)]

    steps = []

    for (name, function) in algorithmList:
        tracer = trace.TraceRecord()
        peak = function(problem, trace=tracer)
        steps.append(tracer.sequence)

        status = "is NOT a peak (INCORRECT!)"
        if problem.isPeak(peak):
            status = "is a peak"

        print(name + " : " + str(peak) + " => " + status)

    # write the trace out to a file
    with open("trace.jsonp", "w") as traceFile:
        traceFile.write("parse(")

        json.dump({"input": problem.array, "steps": steps}, traceFile)

        traceFile.write(")")
Esempio n. 3
0
def main():
    #*****************************射撃王御用*****************************
    if len(sys.argv) > 1:
        problem = loadProblem(sys.argv[1])
    else:
        problem = loadProblem(utils.getOpenFilename("problem.py"))

    # run 射撃王 algorithm, gathering the traces and printing out the results as
    # we go
    algorithm = algorithms.algorithm1

    steps = []

    tracer = trace.TraceRecord()

    # What, if any, should be the return value of shagekiou algorithm?
    shagekiou = algorithm(problem, trace=tracer)
    steps.append(tracer.sequence)

    # status = "is NOT a peak (INCORRECT!)"
    # if problem.isPeak(peak):
    #     status = "is a peak"

    # print(name + " : " + str(peak) + " => " + status)

    # write the trace out to a file
    with open("trace.jsonp", "w") as traceFile:
        traceFile.write("parse(")

        json.dump(
            {
                "input": [problem.height, problem.rising_speed],
                "steps": steps
            }, traceFile)

        traceFile.write(")")