Bindings to CryptoMiniSat, an advanced SAT solver
Actively maintained. Last release 3 weeks ago, commits in 19 of the last 26 weeks. A safe choice.
pip install pycryptosatpycryptosat SAT solver
Python bindings to CryptoMiniSat. The solver runs inside the Python process.
Installing
pip install pycryptosat
To build from source, you need a C++ compiler, GMP and pkg-config (e.g.
sudo apt-get install build-essential libgmp-dev pkg-config or
brew install gmp pkgconf), and network access, since the build downloads
CaDiCaL and CaDiBack. Then, from the root of the repository:
pip install .
Usage
>>> from pycryptosat import Solver
>>> s = Solver()
>>> s.add_clause([1, 2])
>>> s.add_clause([-1])
>>> s.solve()
(True, (None, False, True))
>>> s.solve([-2])
(False, None)
>>> s.get_conflict()
[2]
>>> s.solve()
(True, (None, False, True))
A literal is a non-zero integer: 1 means variable 1 is True, -1 that it is
False. add_clause([1, 2]) adds the clause "1 or 2".
solve() returns (True, solution) if satisfiable, (False, None) if
unsatisfiable, and (None, None) if it ran out of budget. solution is a
tuple starting with None, so that solution[i] is the value of variable i.
solve() optionally takes a list of assumptions: literals that are assumed to
hold for that call only. Above, solve([-2]) is unsatisfiable, but the next
solve() is satisfiable again. After an unsatisfiable solve(),
get_conflict() returns the negation of the assumptions responsible for it.
Solver methods:
add_clause(literals)add_clauses(clauses): a list of clauses, or a flatarray.arrayof zero-terminated clauses (typecodei,lorq)add_xor_clause(variables, rhs): the XOR of the (positive)variablesequals the boolrhssolve(assumptions=None, verbose=None, time_limit=None, confl_limit=None)is_satisfiable():solve(), returning only the first elementget_conflict()nb_vars(): the number of variablesset_option(name, value): see Solver options