Bindings to CryptoMiniSat, an advanced SAT solver
Project description
pycryptosat SAT solver
This directory provides Python bindings to CryptoMiniSat on the C++ level, i.e. when importing pycryptosat, the CryptoMiniSat solver becomes part of the Python process itself.
Installing
pip install pycryptosat
Compiling
If you don't want to use the pip package, you can compile it as:
apt-get install python-dev
python -m build
To help with debug, you can also:
python setup.py bdist_wheel
Usage
The pycryptosat
module has one object, Solver
that has two functions
solve
and add_clause
.
The funcion add_clause()
takes an iterable list of literals such as
[1, 2]
which represents the truth 1 or 2 = True
. For example,
add_clause([1])
sets variable 1
to True
.
The function solve()
solves the system of equations that have been added
with add_clause()
:
>>> from pycryptosat import Solver
>>> s = Solver()
>>> s.add_clause([1, 2])
>>> sat, solution = s.solve()
>>> print sat
True
>>> print solution
(None, True, True)
The return value is a tuple. First part of the tuple indicates whether the
problem is satisfiable. In this case, it's True
, i.e. satisfiable. The second
part is a tuple contains the solution, preceded by None, so you can index into
it with the variable number. E.g. solution[1]
returns the value for
variable 1
.
The solve()
method optionally takes an argument assumptions
that
allows the user to set values to specific variables in the solver in a temporary
fashion. This means that in case the problem is satisfiable but e.g it's
unsatisfiable if variable 2 is FALSE, then solve([-2])
will return
UNSAT. However, a subsequent call to solve()
will still return a solution.
If instead of an assumption add_clause()
would have been used, subsequent
solve()
calls would have returned unsatisfiable.
Solver
takes the following keyword arguments:
time_limit
: the time limit (integer)confl_limit
: the propagation limit (integer)verbose
: the verbosity level (integer)
Both time_limit
and confl_limit
set a budget to the solver. The former is based on time elapsed while the former is based on number of conflicts met during search. If the solver runs out of budget, it returns with (None, None)
. If both limits are used, the solver will terminate whenever one of the limits are hit (whichever first). Warning: Results from time_limit
may differ from run to run, depending on compute load, etc. Use confl_limit
for more reproducible runs.
Example
Let us consider the following clauses, represented using
the DIMACS cnf <http://en.wikipedia.org/wiki/Conjunctive_normal_form>
_
format::
p cnf 5 3
1 -5 4 0
-1 5 3 4 0
-3 -4 0
Here, we have 5 variables and 3 clauses, the first clause being
(x\ :sub:1
or not x\ :sub:5
or x\ :sub:4
).
Note that the variable x\ :sub:2
is not used in any of the clauses,
which means that for each solution with x\ :sub:2
= True, we must
also have a solution with x\ :sub:2
= False. In Python, each clause is
most conveniently represented as a list of integers. Naturally, it makes
sense to represent each solution also as a list of integers, where the sign
corresponds to the Boolean value (+ for True and - for False) and the
absolute value corresponds to i\ :sup:th
variable::
>>> import pycryptosat
>>> solver = pycryptosat.Solver()
>>> solver.add_clause([1, -5, 4])
>>> solver.add_clause([-1, 5, 3, 4])
>>> solver.add_clause([-3, -4])
>>> solver.solve()
(True, (None, True, False, False, True, True))
This solution translates to: x\ :sub:1
= x\ :sub:4
= x\ :sub:5
= True,
x\ :sub:2
= x\ :sub:3
= False
Special options (e.g. LARGEMEM, etc)
In case you need to e.g. have LARGEMEM, you must modify setup.py
and add '-DLARGE_OFFSETS'
to extra_compile_args
. Similarly for other options.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pycryptosat-5.11.10-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57198e3f2596f17c3a27df28d67a2d1845c682e061d2fe2a0321acd3a71f70ac |
|
MD5 | 22ec5831e040916ad69a72e6cb4b0ef3 |
|
BLAKE2b-256 | 3fd0ba44fc801dbcd024fede9b6334f94f0c92a1e6405d046859ca2f3290c6c7 |
Hashes for pycryptosat-5.11.10-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1db6a05780641598e28b3eebf15ce4eaf87ad7476d3b4121967b86542b3e6d23 |
|
MD5 | aa94a35907e44615ea4a726b873f9f62 |
|
BLAKE2b-256 | 3e0b96508ebadf5b1c195789fa7a0d6944705a020a1c5be2c45599dcc6cb9a7d |
Hashes for pycryptosat-5.11.10-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c75ad02eb9cc8f27bdb87653553b66945070904198fc04c524cf00dad872a518 |
|
MD5 | a2dd26145a94f0974b55b98310775ea8 |
|
BLAKE2b-256 | 7da5b3f4e39ea54c2900e5c306db2282951bf9220b4f19b8325be28cb3d99bfe |
Hashes for pycryptosat-5.11.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27e8917c53a9207475e298d8ffc298ee8e87abf589877083df144cace3b51cf4 |
|
MD5 | 1505e7f9839b0bf1b7a94c5528e9711b |
|
BLAKE2b-256 | 8909598c3ec8bde25446d9f861801949afbdf0ffbb87cb2943dbd5eb2c5b071c |
Hashes for pycryptosat-5.11.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb60cc563f94e667a6ef4b4f64a87f01c6abaf6f121253b72db8749cc540761c |
|
MD5 | 4a05580e0a579a9ca0e040084bdd2662 |
|
BLAKE2b-256 | 76075f04e78b43a966f61dfaaf09702165f97afa889cb91e448dcbc657ab2272 |
Hashes for pycryptosat-5.11.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ffe2e36e868fe5fca36151db0d9065fbfbde89ba70515f95766cf02df6234dc |
|
MD5 | 8217727fcea5df00254de3d0e6318b05 |
|
BLAKE2b-256 | 55081a030c1f12648937961e658f266fec5b6a57f3f6b26fe32577cd510c8470 |
Hashes for pycryptosat-5.11.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 858ed391146d48215be23104d8d96837525891e50f78fe7024100df958ce4338 |
|
MD5 | 77a5069ed0678dfa047f94b4f4ae78c4 |
|
BLAKE2b-256 | cebc29d5e1dc856204fe8a124fad4964be938d27373e8e81c6f6f77ab17118b4 |
Hashes for pycryptosat-5.11.10-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35e43bf00526fecf73a747293f0b82ce87d4566481c07d38150b04a3d06e60ef |
|
MD5 | bbc5780234dfc135ebe0c1e68e43d189 |
|
BLAKE2b-256 | 52ff3dc341c52ac187be19eb0a61cba27b1899509edae6c4421dcf6a12bbe122 |