-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_run_prog.py
53 lines (42 loc) · 1.93 KB
/
main_run_prog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import re
from concurrent.futures import ThreadPoolExecutor
from subprocess import Popen
"""
WARNING
The only purpose of this script is to generate solution and stats files from given board input files as fast as possible
Without any adjustment it WILL use 100% CPU and may cause some problems if used without consideration.
"""
def main():
init_file_name_regex = re.compile(r'^[a-zA-Z0-9]+_[0-9]+_[0-9]+.txt$')
orders = ('RDUL', 'RDLU', 'DRUL', 'DRLU', 'LUDR', 'LURD', 'ULDR', 'ULRD')
heuristics = ('manh', 'hamm')
brute_force_methods = ('bfs', 'dfs')
program_command = 'python3.9 -c "import main; main.main()"'
files = [f for f in os.listdir('.') if os.path.isfile(f) and init_file_name_regex.match(f)]
# astr manh 4x4_01_00001.txt solution.txt stats.txt
with ThreadPoolExecutor(max_workers=4) as executor:
for file in files:
executor.submit(sub_method, brute_force_methods, file, heuristics, orders, program_command)
def sub_method(brute_force_methods, input_file, heuristics, orders, program_command):
base_file_name = input_file[:-4]
print(base_file_name)
for method in brute_force_methods:
for order in orders:
sol_file = f'../stats/{base_file_name}_{method}_{order.lower()}_sol.txt'
stats_file = f'../stats/{base_file_name}_{method}_{order.lower()}_stats.txt'
Popen(
[f'{program_command} {method} {order} ../{input_file} {sol_file} {stats_file}'],
shell=True,
cwd="sliding_puzzle"
)
for heuristic in heuristics:
sol_file = f'../stats/{base_file_name}_astr_{heuristic}_sol.txt'
stats_file = f'../stats/{base_file_name}_astr_{heuristic}_stats.txt'
Popen(
[f'{program_command} astr {heuristic} ../{input_file} {sol_file} {stats_file}'],
shell=True,
cwd="sliding_puzzle"
)
if __name__ == '__main__':
main()