Write in separate folders
This commit is contained in:
parent
d969624ff9
commit
d77b88ef9f
|
@ -90,8 +90,8 @@ def find_script(
|
||||||
max_length,
|
max_length,
|
||||||
processes,
|
processes,
|
||||||
timeout,
|
timeout,
|
||||||
|
invalid_prefix,
|
||||||
out_log,
|
out_log,
|
||||||
out_invalid,
|
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
"""
|
"""
|
||||||
Find scripts that satisfy the given set of test cases.
|
Find scripts that satisfy the given set of test cases.
|
||||||
|
@ -100,13 +100,19 @@ def find_script(
|
||||||
:param max_length: maximum script length to test
|
:param max_length: maximum script length to test
|
||||||
:param processes: number of parallel processes to spawn
|
:param processes: number of parallel processes to spawn
|
||||||
:param timeout: maximum allowed time in seconds for each script run
|
:param timeout: maximum allowed time in seconds for each script run
|
||||||
|
:param invalid_prefix: prefix to the files in which invalid scripts
|
||||||
|
are to be stored, one file per script length
|
||||||
:param out_log: stream to which progress logs are written
|
:param out_log: stream to which progress logs are written
|
||||||
:param out_invalid: stream to which invalid scripts are saved
|
|
||||||
:returns: list of matching scripts
|
:returns: list of matching scripts
|
||||||
"""
|
"""
|
||||||
candidates = []
|
candidates = []
|
||||||
bound_check_script = partial(check_script, pairs, timeout)
|
bound_check_script = partial(check_script, pairs, timeout)
|
||||||
|
|
||||||
|
out_invalid = []
|
||||||
|
|
||||||
|
for i in range(max_length + 1):
|
||||||
|
out_invalid.append(open(invalid_prefix + str(i), "w"))
|
||||||
|
|
||||||
chars_count = len(chars)
|
chars_count = len(chars)
|
||||||
num_tasks = int((chars_count ** (max_length + 1) - 1) / (chars_count - 1))
|
num_tasks = int((chars_count ** (max_length + 1) - 1) / (chars_count - 1))
|
||||||
done_tasks = 0
|
done_tasks = 0
|
||||||
|
@ -134,6 +140,9 @@ def find_script(
|
||||||
candidates.append(script)
|
candidates.append(script)
|
||||||
|
|
||||||
if status == Status.Invalid:
|
if status == Status.Invalid:
|
||||||
print(script, file=out_invalid)
|
print(script, file=out_invalid[len(script)])
|
||||||
|
|
||||||
|
for file in out_invalid:
|
||||||
|
file.close()
|
||||||
|
|
||||||
return candidates
|
return candidates
|
||||||
|
|
64
run.py
64
run.py
|
@ -1,37 +1,37 @@
|
||||||
import autogolf
|
import autogolf
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
with open("output/invalid_scripts", "w") as out_invalid:
|
processes = 8
|
||||||
processes = 8
|
timeout = 5 # seconds
|
||||||
timeout = 5 # seconds
|
invalid_prefix = "output/invalid_scripts_"
|
||||||
out_log = sys.stdout
|
out_log = sys.stdout
|
||||||
|
|
||||||
print("\nSearching for identity")
|
print("\nSearching for identity")
|
||||||
identity = autogolf.find_script(
|
identity = autogolf.find_script(
|
||||||
(
|
(
|
||||||
("1", "1"),
|
("1", "1"),
|
||||||
("42", "42"),
|
("42", "42"),
|
||||||
("1984", "1984"),
|
("1984", "1984"),
|
||||||
),
|
),
|
||||||
max_length=3,
|
max_length=3,
|
||||||
processes=processes,
|
processes=processes,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
out_log=out_log,
|
invalid_prefix=invalid_prefix,
|
||||||
out_invalid=out_invalid
|
out_log=out_log,
|
||||||
)
|
)
|
||||||
print("Candidates:", identity)
|
print("Candidates:", identity)
|
||||||
|
|
||||||
print("\nSearching for successor")
|
print("\nSearching for successor")
|
||||||
successor = autogolf.find_script(
|
successor = autogolf.find_script(
|
||||||
(
|
(
|
||||||
("1", "2"),
|
("1", "2"),
|
||||||
("42", "43"),
|
("42", "43"),
|
||||||
("1984", "1985"),
|
("1984", "1985"),
|
||||||
),
|
),
|
||||||
max_length=5,
|
max_length=5,
|
||||||
processes=processes,
|
processes=processes,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
out_log=out_log,
|
invalid_prefix=invalid_prefix,
|
||||||
out_invalid=out_invalid
|
out_log=out_log,
|
||||||
)
|
)
|
||||||
print("Candidates:", successor)
|
print("Candidates:", successor)
|
||||||
|
|
Loading…
Reference in New Issue