-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
41 lines (35 loc) · 1.16 KB
/
test.py
File metadata and controls
41 lines (35 loc) · 1.16 KB
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
from pathlib import Path
import dsatpy
import json, time
def cpp_json_to_bitset_cnf(
fpath: Path
) -> tuple[list[int], list[tuple[tuple[int, dsatpy.BitSet], ...]]]:
with open(fpath, 'r') as f:
data = json.load(f)
vs = [card for _, card in data["vars"]]
cnf = []
for c in data["clauses"]:
cnf.append([(var_idx - 1,
dsatpy.BitSet.from_decimal_string(str(decimal_str)))
for var_idx, decimal_str in c])
return vs, cnf
def tmp_run_dsat(
discrete_vars: list[int],
cnf: list[list[tuple[int, dsatpy.BitSet]]],
solver: dsatpy.Solver | None = None):
if solver is None:
solver = dsatpy.Solver()
tic = time.perf_counter()
solver.init(discrete_vars, cnf)
is_sat = solver.solve()
toc = time.perf_counter()
runtime = toc - tic
avg_strength = solver.t_strength / (solver.n_added_cdc + 1)
return is_sat, runtime
def dsat_cpp_wrapper(cnf_path: Path) :
vs, clauses = cpp_json_to_bitset_cnf(cnf_path)
return tmp_run_dsat(vs, clauses)
if __name__ == "__main__":
import sys
results = dsat_cpp_wrapper(Path(sys.argv[1]))
print(results)