-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_experiments.py
60 lines (47 loc) · 1.71 KB
/
run_experiments.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
import csv
import os
import numpy as np
from utils import DP
def main():
base_dirname = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tests', 'samples')
dirnames = [f.path for f in os.scandir(base_dirname) if f.is_dir()]
samples = 30
reps = 30
testcases = samples * len(dirnames)
# Choose strategy. (1 - 5)
s = 5
if s == 2 or s == 4:
repetition = 1
rows = 1
else:
repetition = reps
rows = reps
with open('./experiment_s{}.csv'.format(s), 'w', newline='') as csv_file:
writer = csv.writer(csv_file)
statistics = np.empty((rows, testcases), dtype=np.float)
i = 0
print('Strategy {}:'.format(s))
for i_r in np.arange(repetition):
print('Repetition: {}'.format(i_r + 1))
with open('./experiment_s{}.csv'.format(s), 'a', newline='') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(['Repetition: {}'.format(i_r + 1)])
j = 0
for dirname in dirnames:
filenames = os.listdir(dirname)
for file in filenames:
file = os.path.join(base_dirname, dirname, file)
print('Processing: ' + file)
sat_solver = DP(file)
sat_solver.split = s
clauses = sat_solver.read()
clauses = sat_solver.tautology(clauses)
var = sat_solver.solver(clauses)
statistics[i, j] = sat_solver.count
j += 1
with open('./experiment_s{}.csv'.format(s), 'a', newline='') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(statistics[i, :].tolist())
i += 1
if __name__ == '__main__':
main()