From f36e9ed1caf9e2577c2215c6ca08877aa4729626 Mon Sep 17 00:00:00 2001 From: Alexander Fedotov Date: Sun, 13 Mar 2016 10:58:15 +0100 Subject: [PATCH] started with a python runner script --- code/SokRunner.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 code/SokRunner.py diff --git a/code/SokRunner.py b/code/SokRunner.py new file mode 100644 index 0000000..1a92e32 --- /dev/null +++ b/code/SokRunner.py @@ -0,0 +1,58 @@ +import os, errno +import subprocess + +#solver path +solverpath = "C:\\Users\\Alex Fedotov\\Documents\\Studies\\Model Checking\\Assignments\\Solver\\" + +#paths to folders with sokoban screens +paths = ["C:\\Users\\Alex Fedotov\\Documents\\Studies\\Model Checking\\Assignments\\Sokoban\\screens", + ] + +#path to output folder (base) +output = "C:\\Users\\Alex Fedotov\\Documents\\Studies\\Test" + +commands = ["C:\\Users\\Alex Fedotov\\Documents\\Studies\\Model Checking\\Assignments\\Solver\\solver.exe"] + +boxbound = 3 +sizebound = 60 +timebound = 10 + +def checkPaths(): + isOk = True + for path in paths: + if not os.path.isdir(path): + isOk = False + print("You specified a wrong path: %s" % path) + return isOk + +def checkScreen(screenpath): + scrSize = 0 + scrBox = 0 + with open(screenpath,"r") as src: + for line in src: + scrSize += len(line.rstrip()) + scrBox += line.count('$') + scrBox += line.count('*') + src.close() + return boxbound >= scrBox and sizebound >= scrSize + +for com in commands: + if checkPaths(): + out = open(output + "\\results.txt", "w") + for path in paths: + all_rs = os.listdir(path) + for test in all_rs: + input_path = path + "\\" + test + os.makedirs(output, exist_ok=True) + os.chdir(solverpath) + if checkScreen(input_path): + runcommand = [] + runcommand.append(com) + runcommand.append(input_path) + #to be continued... + proc = subprocess.run(runcommand, stdout=subprocess.PIPE, universal_newlines=True) + proc.wait() + out.write(test + ":" + proc.stdout) + print(test + ":" + proc.stdout) + #input("Press enter to continue...") + out.close(); -- 2.20.1