-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_schlandals_benchmarks.py
66 lines (56 loc) · 2.23 KB
/
make_schlandals_benchmarks.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
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
import os
import random
random.seed(697458)
script_dir = os.path.dirname(os.path.realpath(__file__))
uai_dir = os.path.join(script_dir, 'bayesian-networks', 'uai')
outdir = os.path.join(script_dir, 'bench-input')
os.makedirs(outdir, exist_ok=True)
def _get_uai_queries(filename):
with open(os.path.join(uai_dir, filename)) as f:
content = f.read().split()
number_var = int(content[1])
vars_domain_size = [int(content[2 + i]) for i in range(number_var)]
idx = 2 + number_var + 1
scopes = []
for _ in range(number_var):
scope_size = int(content[idx])
idx += 1
scopes.append([int(content[idx + i]) for i in range(scope_size)])
idx += scope_size
is_leaf = [True for _ in range(number_var)]
for variable in range(number_var):
for parent in scopes[variable][:-1]:
is_leaf[parent] = False
queries = []
for variable in range(number_var):
if is_leaf[variable]:
value = random.randint(0, vars_domain_size[variable] - 1)
#for value in range(vars_domain_size[variable]):
queries.append(f'1 {variable} {value}')
return queries
def make_opti_bench():
instances = [f for f in os.listdir(uai_dir) if os.path.isfile(os.path.join(uai_dir, f))]
with open(os.path.join(outdir, 'opti-benchs.csv'), 'w') as f:
f.write('model,query')
for model in instances:
if 'fs' in model or 'blockmap' in model or 'mastermind' in model:
continue
f.write('\n')
queries = _get_uai_queries(model)
print(f"Parsing {model}: {len(queries)} queries")
model_path = os.path.join(uai_dir, model)
f.write('\n'.join([f'{model_path},{query}' for query in queries]))
def make_learn_bench():
pass
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: python make_schlandals_benchmarks.py [opti|learn]")
sys.exit(1)
if sys.argv[1] == 'opti':
make_opti_bench()
elif sys.argv[1] == 'learn':
make_learn_bench()
else:
print("Usage: python make_schlandals_benchmarks.py [opti|learn]")
sys.exit(1)