started with a python runner script
authorAlexander Fedotov <Alexander Fedotov>
Sun, 13 Mar 2016 09:58:15 +0000 (10:58 +0100)
committerAlexander Fedotov <Alexander Fedotov>
Sun, 13 Mar 2016 09:58:15 +0000 (10:58 +0100)
code/SokRunner.py [new file with mode: 0644]

diff --git a/code/SokRunner.py b/code/SokRunner.py
new file mode 100644 (file)
index 0000000..1a92e32
--- /dev/null
@@ -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();