diff options
| author | Tom Harley | 2019-01-27 15:37:06 +0000 |
|---|---|---|
| committer | Tom Harley | 2019-01-27 15:37:06 +0000 |
| commit | a996283af7c21baaff0e114d58c34db820902c6f (patch) | |
| tree | 2fe5b6f7a800d4a7b8a65ee345f8c98aa138e36b /solvitaire/archive/optimisation-test.py | |
| parent | Split code into 3 files (diff) | |
| download | metasol-a996283af7c21baaff0e114d58c34db820902c6f.tar.gz metasol-a996283af7c21baaff0e114d58c34db820902c6f.zip | |
Reorganise repo
All solvitaire content has been shoved into a subdirectory to tidy up the root of the project. This also means solvitaire is treated similarly to other dependencies of the project, and allows other dependencies to be added easily.
There’s also a lot of other work done here, such as usign a thread pool library to manage the running of the voters.
Diffstat (limited to 'solvitaire/archive/optimisation-test.py')
| -rw-r--r-- | solvitaire/archive/optimisation-test.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/solvitaire/archive/optimisation-test.py b/solvitaire/archive/optimisation-test.py new file mode 100644 index 0000000..594b9eb --- /dev/null +++ b/solvitaire/archive/optimisation-test.py @@ -0,0 +1,75 @@ +import sys +from subprocess import run, CalledProcessError, DEVNULL, PIPE, Popen + +runCount = 100 + +# Loops through each canonical solitaire + +for optimisation in [ + "-no-reduced-state", + "-no-pile-symmetry", + "-no-auto-foundations", + "-no-symmetry" +]: + + for preset in [ + "simple-alpha-star", + "simple-bakers-dozen", + "simple-black-hole", + "simple-canfield", + "simple-flower-garden", + "simple-fortunes-favor", + "simple-free-cell", + "simple-somerset", + "simple-spanish-patience" + ]: + + differs = [] + + for attempt in range(runCount): + try: + op_p = Popen("./cmake-build-release/bin/solvitaire" + optimisation + + " --type " + preset + " --random " + str(attempt) + + " --classify", + shell=True, + stdout=PIPE, + stderr=DEVNULL) + out_str = op_p.stdout.readline() + if out_str == b'Solved\n': + op_res = True + elif out_str == b'No Possible Solution\n': + op_res = False + else: + raise Exception('Invalid return value!') + + no_op_p = Popen("./cmake-build-release/bin/solvitaire" + + " --type " + preset + " --random " + str(attempt) + + " --classify", + shell=True, + stdout=PIPE, + stderr=DEVNULL) + out_str = no_op_p.stdout.readline() + if out_str == b'Solved\n': + no_op_res = True + elif out_str == b'No Possible Solution\n': + no_op_res = False + else: + raise Exception('Invalid return value!') + + if op_res != no_op_res: + differs.append(attempt) + + except CalledProcessError: + print("Error running " + preset + " with seed " + str(attempt) + "!") + sys.exit() + except Exception as e: + print("Unknown error in script: ", e) + sys.exit() + + run("pkill solvitaire", shell=True) + + if not differs : + print(preset + ": No difference in solutions for " + optimisation) + else : + print(preset + ": Optimisation " + optimisation + " differs for the following seeds:") + print(differs) |
