-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (39 loc) · 1.4 KB
/
main.py
File metadata and controls
47 lines (39 loc) · 1.4 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
42
43
44
45
46
47
import time
import numpy as np
from pysat.formula import CNF
from pysat.solvers import Solver
from satlll import lll_generator
from satlll import lll_decision
from satlll import lll_solver
if __name__ == "__main__":
# generator
n = 500 # variable numbers
sat_instance = lll_generator(n, 5)
print(f"the size of SAT: {len(sat_instance)}")
print("----------")
# decision algorithm
start_time = time.time()
satisfiable = lll_decision(sat_instance, n, eval_iter=10)
print(f"LLL satisfiable: {satisfiable}")
print(f"desision time: {time.time() - start_time:.4f}")
print("----------")
# lll solver (search)
start_time = time.time()
model = lll_solver(sat_instance, n)
if model:
print(f"The SAT instance can be solved by algorithmic LLL")
print(f"solving time: {time.time() - start_time:.4f}")
print("----------")
# lll solver (sample)
start_time = time.time()
model = lll_solver(sat_instance, n, sample=True)
if model:
print(f"The SAT instance can be solved by partial rejection sampling")
print(f"solving time: {time.time() - start_time:.4f}")
print("----------")
# modern solver
cnf = CNF(from_clauses=sat_instance)
start_time = time.time()
with Solver(bootstrap_with=cnf) as solver:
print(f"The SAT instance can be solved: {solver.solve()}")
print(f"solving time: {time.time() - start_time:.4f}")