GithubHelp home page GithubHelp logo

pysathq / pysat Goto Github PK

View Code? Open in Web Editor NEW
384.0 384.0 69.0 9.07 MB

A toolkit for SAT-based prototyping in Python

Home Page: https://pysathq.github.io/

License: MIT License

C++ 32.73% Python 59.17% Makefile 0.25% C 0.17% Shell 0.06% CSS 2.62% HTML 3.43% JavaScript 0.72% SCSS 0.85%

pysat's People

Contributors

alexeyignatiev avatar aoertel avatar blyxxyz avatar boltmaud avatar brandhsn avatar brossignol avatar chrisjefferson avatar davidferrerbeltran avatar lytr777 avatar marino-mrc avatar miguelterraneves avatar mvcisback avatar odidev avatar rexyuan avatar rjungbeck avatar ruancomelli avatar thibaultfalque avatar thomaoc1 avatar yxliang01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pysat's Issues

WCNFPlus parser does not work

import pysat.formula

wcnfp.append([list(range(100)), 50], is_atmost=True)
wcnfp.to_file("test.wcnf")
wcnfp1=pysat.formula.WCNFPlus(from_file="test.wcnf")

Produces:

 wcnfp1=pysat.formula.WCNFPlus(from_file="test.wcnf")
  File "formula.py", line 1535, in __init__
    from_string=from_string, comment_lead=comment_lead)
  File "formula.py", line 918, in __init__
    self.from_file(from_file, comment_lead, compressed_with='use_ext')
  File "formula.py", line 958, in from_file
    self.from_fp(fobj.fp, comment_lead)
  File "formula.py", line 1576, in from_fp
    cl = [int(l) for l in line.split()[:-1]]
  File "formula.py", line 1576, in <listcomp>
    cl = [int(l) for l in line.split()[:-1]]
ValueError: invalid literal for int() with base 10: '<='

The reason seems to be the wrong test for atmost clause in formula.py 1575

 if line[-1] == '0':  # normal clause

which is true whenever the cardinality value ends with a 0 digit.

RC2-MaxSAT-Solver cannot solve the instances from MaxSAT-Evaluation2012 (unweighted random track)?

Hi,

Thank you very much for providing such a clean interface to the state-of-the-art SAT solvers in python. It does save a lot of time of mine.

I am new to this field and want to find a MaxSAT solver that performs well and that is easy to use. Your RC2-MaxSAT-solver in the pysat.examples.rc2 module seems to be a good choice. The solver performs perfectly on simple instances. However, when I evaluate the solver on the benchmark provided by MaxSAT-Evaluation2012 (unweighted-random-track), it seems that the solver cannot solve even one single instance. My program just won't stop.

This seems really unnormal. Could you please help me solve this problem? Thank you very much!
(One potential problem that I identify is that the solver only utilizes one single CPU core, which seems to be irregular for an optimization tool?)

The core of my codes is as follows:

def compute_solution(path):                                                                                                        
    if '.cnf' in path:                                                                                                             
        sat = CNF(path).weighted()                                                                                                 
    elif '.wcnf' in path:                                                                                                          
        sat = WCNF(path)                                                                                        
    else:                                                                                                       
        raise ValueError("Wrong format of the formula file: %s"%path)                                           
    cost, solutions = sat.topw, []                                                             
    with RC2Stratified(sat) as rc2:                                        
        for m in rc2.enumerate():
            print(m, rc2.cost, cost)                                          
            if rc2.cost > cost:                                  
                break                               
            else:                       
                cost = rc2.cost                                                  
                solutions.append(m)                                
    return sum(sat.wght)-cost, solutions

Bad zip file or tar file

Hi Alexey,

I tried installing PySAT via pip and compiling the source code, but errors are thrown while compiling maplesat, minicard and minisatgh. The type of errors is the same -- the downloaded tar or zip files could not be recognized. The dump for maplesat is as below:

preparing maplesat
downloading: solvers/maplesat.zip (675 bytes)... done
extracting solvers/maplesat.zip
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-zsQP_s/python-sat/setup.py", line 118, in
install_requires=['pypblib>=0.0.3', 'six']
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 61, in run
return orig.install.run(self)
File "/usr/lib/python2.7/distutils/command/install.py", line 601, in run
self.run_command('build')
File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/tmp/pip-build-zsQP_s/python-sat/setup.py", line 67, in run
prepare.do(to_install)
File "/tmp/pip-build-zsQP_s/python-sat/solvers/prepare.py", line 281, in do
extract_archive(sources[solver][-1], solver)
File "/tmp/pip-build-zsQP_s/python-sat/solvers/prepare.py", line 365, in extract_archive
myzip = zipfile.ZipFile(archive, 'r')
File "/usr/lib/python2.7/zipfile.py", line 770, in init
self._RealGetContents()
File "/usr/lib/python2.7/zipfile.py", line 811, in _RealGetContents
raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file

----------------------------------------

Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-zsQP_s/python-sat/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-X4QLE2-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-zsQP_s/python-sat/

The dump for minisat is:

preparing minicard
downloading: solvers/minicard.tar.gz (675 bytes)... done
extracting solvers/minicard.tar.gz
Traceback (most recent call last):
File "setup.py", line 120, in
install_requires=['pypblib>=0.0.3', 'six']
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/lib/python2.7/distutils/command/install.py", line 601, in run
self.run_command('build')
File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 69, in run
prepare.do(to_install)
File "/home/u1718431/Downloads/pysat/solvers/prepare.py", line 281, in do
extract_archive(sources[solver][-1], solver)
File "/home/u1718431/Downloads/pysat/solvers/prepare.py", line 352, in extract_archive
tfile = tarfile.open(archive, 'r:gz')
File "/usr/lib/python2.7/tarfile.py", line 1693, in open
return func(name, filemode, fileobj, **kwargs)
File "/usr/lib/python2.7/tarfile.py", line 1751, in gzopen
raise ReadError("not a gzip file")
tarfile.ReadError: not a gzip file

For now, I have removed the three solvers from the to_install list, and the installation completes. But help in getting the installation right would be appreciated.

Thanks!

PyPBLib PB to CNF encoder

I'm trying to convert simple pb constraint to CNF but it seems not to work.

e.g. x1 + x2 + x3 .... = 1 always returns the same CNF regardless encoder used.

Attached my code.

If I use cardinality encoding it works for different encoders I get
different CNF output. Also attached example.

I assume that something is wrong with PBConfig that it ignores
PB_Encoder value set.

Describe the bug

PBLib converts PB constraint to CNF always the same way regardless encoder used i.e. PBConfig.PB_Encoder
Expected behavior

Expected output CNF should differ in variables and clauses not always the same.
To Reproduce

Conversion to CNF with cardinality encoder works as expected. Code for both to compare attached.
from pypblib import pblib
from pypblib.pblib import PBConfig, Pb2cnf
max = 129
lits=list(range(1,max))
wlits=[]
print(lits)
weights=[]
for x in lits:
weights.append(1)
wlits.append(pblib.WeightedLit(x, 1))

print("Number of weights %d" % len(weights))

pb_encoders=[pblib.PB_BDD,pblib.PB_SWC, pblib.PB_SORTINGNETWORKS, pblib.PB_ADDER, pblib.PB_BINARY_MERGE]

for x in pb_encoders:
print("Encoding PB %d" % (x))

config = PBConfig()
config.set_PB_Encoder(pblib.PB_BDD)
#print(config)

formula = []
pb2 = Pb2cnf(PBConfig())
max_var = pb2.encode_both(weights,lits, 1,1, formula, max)
print("Number of variables %d" % max_var)
print("Number of clauses %d" % len(formula) )

constr = pblib.PBConstraint(wlits, pblib.BOTH, 1)
aux_var = pblib.AuxVarManager(max)
formula = pblib.VectorClauseDatabase(config)
pb2cnf = pblib.Pb2cnf(config)
pb2cnf.encode(constr, formula, aux_var)
print("Number of variables %d" % aux_var.get_biggest_returned_auxvar() )
print("Number of clauses %d" % formula.get_num_clauses() )

from pysat import *
from pysat.pb import *
from pysat.card import *

lits=list(range(1,129))
print(lits)

for x in range(1,6):
print("Encoding PB %d" % (x))
cnf = PBEnc.equals(lits=lits, encoding=x)
print(cnf.clauses)

print("Number of variables %d" % cnf.nv)
print("Number of clauses %d" % len(cnf.clauses) )

print("****************************")

for x in range(0, 9):
print("Encoding SAT %d" % (x))
cnf = CardEnc.equals(lits=lits, encoding=x)
print(cnf.clauses)

print("Number of variables %d" % cnf.nv)
print("Number of clauses %d" % len(cnf.clauses) )

Running pysat with PyPy

Since some of my SAT problems take some time, I thought it would be a nice idea to see if runtime can be improved by using PyPy instead of CPython. Unfortunately

pypy3 -m pip install python-sat

fails.

Before pasting the extremely long setup/error log, I wanted to ask whether PyPy compatibility is even intended, i.e. if pysat installation under PyPy should even work in principle.

My version is:

Python 3.6.9 (78d4c48fa091, Apr 30 2020, 07:55:31)
[PyPy 7.3.1 with GCC 10.0.1 20200328 (Red Hat 10.0.1-0.11)] on linux

[Win10 x64, Python 3.8.2] ImportError: DLL load failed while importing pycard: The specified module could not be found.

Hi there.

test.py:
import pysat.card

> python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import pysat.card
  File "C:\Users\rtentser\AppData\Local\Programs\Python\Python38\lib\site-packages\pysat\card.py", line 99, in <module>
    import pycard
ImportError: DLL load failed while importing pycard: The specified module could not be found.

I use 0.1.5.dev4 (because more recent versions fail to install). Installed with pip.

Setup failing due to broken links

Hi Alexey,

I have had an issue a few times with broken links for the SAT solvers during the pysat installation. This is particularly severe in my case because pysat is part of a testing pipeline that is run for each PR, which requires installing pysat in a VM every time. Because of this, from time to time, all our tests start failing because of a broken link in pysat, even if the code being pushed does not use pysat.

This problem would be fixed if the SAT solvers were part of pysat itself instead of automatically downloaded at setup time. Is there any particularly strong reason why you opted for the latter solution?

How to append negated clause to the formula?

Clauses passed to the formula must have logical disjunction form. Lets assume I have following clause in conjunction form 1 and -2 and -3, using the De Morgan's laws I can convert it to -[-1, 2, 3]. However is it possible to add negated clause to the formula? What is the standard procedure in such case?

Parallelisation support

I was wondering if there is any current support for parallelisation (I want to solve multiple SAT problems at the same time).

Is either Python threads (you could release the GIL?), or multiprocessing supported?

invalid number of variables

Hello, not exactly sure if this is an issue, but
when I call
cnf = CNF('test.cnf')
cnf.nv
I get 19 as a result, i know its an invalid CNF because in preamble I state that there will be 50 vars.
Is that ok and I am supposed to feed CNF only with correct input?

What happens when i state in preamble 50 variables, but then in actual clauses only 30 variables are used?
Should i expect .nv to return 50 or 30?

Thank you in advance for answers

test.cnf:
p cnf 50 91
4 -18 19 0
3 18 -5 0

Installation fails with "EOF occurred in violation of protocol" after preparing minicard

Running

sudo pip install python-sat

fails resulting in the following output:

Collecting python-sat
  Downloading python-sat-0.1.2dev7.tar.gz (88kB)
Requirement already satisfied: six in /usr/local/lib/python2.7/dist-packages (from python-sat)
Installing collected packages: python-sat
  Running setup.py install for python-sat: started
    Running setup.py install for python-sat: finished with status 'error'
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-gElFxn/python-sat/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-m1cUf1-record/install-record.txt --single-version-externally-managed --compile:
    /usr/local/lib/python2.7/dist-packages/setuptools-36.6.0-py2.7.egg/setuptools/dist.py:351: UserWarning: Normalizing '0.1.2dev7' to '0.1.2.dev7'
    running install
    running build
    preparing glucose30
    downloading: solvers/glucose30.tar.gz (50813 bytes)... done
    extracting solvers/glucose30.tar.gz
    adapting glucose30's files
    patching glucose30
    patching file solvers/glucose30/Makefile
    patching file solvers/glucose30/core/BoundedQueue.h
    patching file solvers/glucose30/core/Solver.cc
    patching file solvers/glucose30/core/Solver.h
    patching file solvers/glucose30/core/SolverTypes.h
    patching file solvers/glucose30/mtl/Alg.h
    patching file solvers/glucose30/mtl/Alloc.h
    patching file solvers/glucose30/mtl/Heap.h
    patching file solvers/glucose30/mtl/IntTypes.h
    patching file solvers/glucose30/mtl/Map.h
    patching file solvers/glucose30/mtl/Queue.h
    patching file solvers/glucose30/mtl/Sort.h
    patching file solvers/glucose30/mtl/Vec.h
    patching file solvers/glucose30/mtl/XAlloc.h
    patching file solvers/glucose30/utils/Options.cc
    patching file solvers/glucose30/utils/Options.h
    patching file solvers/glucose30/utils/ParseUtils.h
    patching file solvers/glucose30/utils/System.cc
    patching file solvers/glucose30/utils/System.h
    compiling glucose30
    c++ -std=c++11 -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -I.. -O3 -DNDEBUG -c core/Solver.cc -o core/Solver.o
    c++ -std=c++11 -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -I.. -O3 -DNDEBUG -c utils/Options.cc -o utils/Options.o
    c++ -std=c++11 -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -I.. -O3 -DNDEBUG -c utils/System.cc -o utils/System.o
    preparing glucose41
    downloading: solvers/glucose41.tar.gz (82779 bytes)... done
    extracting solvers/glucose41.tar.gz
    adapting glucose41's files
    patching glucose41
    patching file solvers/glucose41/Makefile
    patching file solvers/glucose41/core/BoundedQueue.h
    patching file solvers/glucose41/core/Solver.cc
    patching file solvers/glucose41/core/Solver.h
    patching file solvers/glucose41/core/SolverStats.h
    patching file solvers/glucose41/core/SolverTypes.h
    patching file solvers/glucose41/mtl/Alg.h
    patching file solvers/glucose41/mtl/Alloc.h
    patching file solvers/glucose41/mtl/Clone.h
    patching file solvers/glucose41/mtl/Heap.h
    patching file solvers/glucose41/mtl/IntTypes.h
    patching file solvers/glucose41/mtl/Map.h
    patching file solvers/glucose41/mtl/Queue.h
    patching file solvers/glucose41/mtl/Sort.h
    patching file solvers/glucose41/mtl/Vec.h
    patching file solvers/glucose41/mtl/VecThreads.h
    patching file solvers/glucose41/mtl/XAlloc.h
    patching file solvers/glucose41/utils/Options.cc
    patching file solvers/glucose41/utils/Options.h
    patching file solvers/glucose41/utils/ParseUtils.h
    patching file solvers/glucose41/utils/System.cc
    patching file solvers/glucose41/utils/System.h
    compiling glucose41
    c++ -std=c++11 -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -DINCREMENTAL -I.. -O3 -DNDEBUG -c core/Solver.cc -o core/Solver.o
    core/Solver.cc: In member function ‘void Glucose41::Solver::analyze(Glucose41::CRef, Glucose41::vec<Glucose41::Lit>&, Glucose41::vec<Glucose41::Lit>&, int&, unsigned int&, unsigned int&)’:
    core/Solver.cc:775:49: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if(chanseokStrategy && nblevels <= coLBDBound) {
                                                     ^
    core/Solver.cc: In member function ‘void Glucose41::Solver::adaptSolver()’:
    core/Solver.cc:1417:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(c.lbd() <= coLBDBound) {
                            ^
    core/Solver.cc: In member function ‘Glucose41::lbool Glucose41::Solver::search(int)’:
    core/Solver.cc:1563:49: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if(chanseokStrategy && nblevels <= coLBDBound) {
                                                     ^
    c++ -std=c++11 -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -DINCREMENTAL -I.. -O3 -DNDEBUG -c utils/Options.cc -o utils/Options.o
    c++ -std=c++11 -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -DINCREMENTAL -I.. -O3 -DNDEBUG -c utils/System.cc -o utils/System.o
    preparing lingeling
    downloading: solvers/lingeling.tar.gz (501731 bytes)... done
    extracting solvers/lingeling.tar.gz
    adapting lingeling's files
    extracting solvers/lingeling/druplig-009.zip
    extracting solvers/lingeling/lingeling-bbc-9230380-160707.tar.gz
    patching lingeling
    patching file solvers/lingeling/Makefile
    patching file solvers/lingeling/druplig.h
    patching file solvers/lingeling/lglib.h
    patching file solvers/lingeling/lglopts.h
    compiling lingeling
    cc -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -I. -DNLGLOG -DNDEBUG -DNCHKSOL -DNLGLYALSAT -DNLGLFILES -DNLGLDEMA -DVERSION=\"PYSAT\" -c lglib.c -o lglib.o
    cc -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -I. -DNLGLOG -DNDEBUG -DNCHKSOL -DNLGLYALSAT -DNLGLFILES -DNLGLDEMA -DVERSION=\"PYSAT\" -c lglopts.c -o lglopts.o
    cc -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -I. -DNLGLOG -DNDEBUG -DNCHKSOL -DNLGLYALSAT -DNLGLFILES -DNLGLDEMA -DVERSION=\"PYSAT\" -c druplig.c -o druplig.o
    preparing minicard
    error: [Errno socket error] EOF occurred in violation of protocol (_ssl.c:590)
    
    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-5F33G2/python-sat/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-5DCH8z-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-5F33G2/python-sat/

FWIW, the issue occurs when cloning the repository and running install on that.

Am I missing something obvious, or any idea?

Requiring the AND of two bit vectors two have at most k true values

Suppose we have two bit vectors (always of the same length). We'd like to express that the bitwise AND of the two contains at most k true values. Is there a neat way of doing this via PySAT?

So for instance, suppose we had two vectors consisting of the variables [1,2,3] and [4,5,6]. If k was equal to 1, we'd be fine if the variables took Boolean values such that they were [0,1,1] and [0,0,1] since now the third position is the only position where both vectors have a 1. On the other hand, if the vectors were [0,1,1] and [1,1,1] this would not be OK, since the 2nd and 3rd position have a true value after the AND.

I suppose that in theory, one solution is to have three new variables to correspond to the ANDs of the individual bits and then requiring these three bits to have at most k values true. But then again I'm not so sure how to really express this.

Parallel solving

Hello, is it possible to utilize more threads/cores when solving a SAT problem? Currently I'm using Glucose4. If not, is it even possible in principle?

`CardEnc.atmost` resets `vpool.top` when `len(lits) <= bound`

As the title says, when attempting to enforce a trivial at-most constraint (the bound is greater than or equal to the number of literals), which is represented by the empty set of clauses, and when an IDPool is passed as a parameter, the IDPool's .top member is erroneously reset to 0, causing subsequently created variables to overwrite existing ones.

While this issue can easily be worked around by checking whether the bound is trivial during encoding, it may still introduce nasty bugs when one relies on it.

Below is a minimal snippet that reproduces the bug.

from pysat.formula import IDPool
from pysat.card import CardEnc

vp = IDPool()
n = 20
b = 50
assert n <= b

lits = [vp.id(v) for v in range(1, n+1)]
top = vp.top

G = CardEnc.atmost(lits, b, vpool=vp)

assert len(G.clauses) == 0

try:
    assert vp.top >= top 
except AssertionError as e:
    print(f"\nvp.top = {vp.top} (expected >= {top})\n")
    raise e

running python setup.py install fails (linux)

When i run python setup.py install, it fails with following error

building 'pysolvers' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-UKCoZ3/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Isolvers -I/usr/include/python2.7 -c solvers/pysolvers.cc -o build/temp.linux-x86_64-2.7/solvers/pysolvers.o -std=c++11 -Wall -Wno-deprecated -DWITH_CADICAL -DWITH_GLUCOSE30 -DWITH_GLUCOSE41 -DWITH_LINGELING -DWITH_MAPLECHRONO -DWITH_MAPLECM -DWITH_MAPLESAT -DWITH_MINICARD -DWITH_MINISAT22 -DWITH_MINISATGH
solvers/pysolvers.cc:21:10: fatal error: cadical/cadical.hpp: No such file or directory
 #include "cadical/cadical.hpp"
          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Installation succeeds if I first run

python setup.py build

and then

python setup.py install

It seems that python setup.py install doesn't download sat solvers.

Is there any way to solve DNF formulas?

Greetings,

I am trying to use PySAT to solve some non-CNF formulas, concretly, most of my formulas are in DNF. I make thousand of calls to the solver and I'm very interested in performance, so I can't transform formulas to CNF all the time, Is there any way to work directly with non-CNF formulas?

Thank you in advance!

On Parsimonious Cardinality Encodings

Hi Alexey,

I have been using PySAT for creating CNFs that I run counters or samplers on, and the different cardinality constraint encoding options of PySAT are especially useful. However, not all encodings preserve the number of solutions, some not even after projecting on original variables. I thought it would be useful to share with others (and maybe even integrate into PySAT somehow), information on which encodings are parsimonious and which are not, and which encodings are fastest wrt counting/sampling.

Equality constraints with bound > 1 (eg: enforce exactly 5 out of 10 variables should be true):
Encodings that give correct count without projection: 7,8,1 (best to worst in terms of speed for D4 model counter)
Encodings that give correct count when projecting on original variables: 7,8,6,3,2,1 (best to worst in terms of speed for ApproxMC)

Equality constraints with bound = 1 (eg: enforce exactly 1 out of 10 vars to be true)
Encodings that give correct count without projection: 0,1,4,5,7,8
Encodings that give correct count when projecting on original variables: 0 through 8 (9 doesn't give correct answer)
Note: In terms of speed, solving just one exact-1 constraint is usually very fast so encoding doesn't matter much. However with multiple exact-1 constraints over overlapping sets of variables, I found that encodings 4 or 5 generally seemed to be the fastest for counting (YMMV).

NB: I have not performed rigorous experiments to compare speed; this is meant more as 'rule of thumb' when trying to get a working prototype. I have consistently gotten correct answers when using encodings mentioned above for the respective purposes. It maybe possible to make other encodings give correct counts too somehow, but I was unable to find a way.

Depend on py-aiger-cnf instead of py-aiger

Hello,

I see that pysat now supports using py-aiger inputs (very cool!)

It looks like it's only being used as input and then being converted to CNF. If so, it might be better to depend on py-aiger-cnf.

  • This package tracks py-aiger development so it should isolate you API changes.
  • py-aiger-cnf also woks some of the ecosystem libraries such as the bitvector extensions (py-aiger-bv), (really anything that exports an aig attribute).

I would be happy to help with the integration.

Solver get_core() returns None even if UNSAT

According to doc, get_core() returns None only if previous call is not UNSAT. However, I found a case that violates the instruction.

How to reproduce:

import json
from pysat.solvers import Solver
with open('clauses.txt') as infile:
    clauses = json.load(infile)
with Solver(bootstrap_with=clauses) as s:
    print(s.solve())  # --> False
    print(s.get_core())  # --> None

clauses.txt

Thanks

Problem with py-aiger + python 2.7

Hi Alexey,

I freshly pip-installed the latest version of pysat, and there appears to be some problem with py-aiger. I get the following error when I import pysat in my script:

Traceback (most recent call last):
File "countPM.py", line 2, in
from pysat.formula import CNF, IDPool
File "/usr/local/lib/python2.7/dist-packages/pysat/formula.py", line 209, in
import aiger
File "/usr/local/lib/python2.7/dist-packages/aiger/init.py", line 2, in
from aiger.aig import AIG
File "/usr/local/lib/python2.7/dist-packages/aiger/aig.py", line 12
return f"{name}##time_{time}"
^
SyntaxError: invalid syntax

I presume this has to do with using python2.7 and py-aiger. I am running Ubuntu 16.04 and py-aiger is the version automatically fetched when installing pysat. Thanks!

cannot install pysat cdf package

i have error while installing pysat cdf. the error message is shown below :

ERROR: Command errored out with exit status 1:
command: 'c:\users\asus\appdata\local\programs\python\python36\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ASUS\AppData\Local\Temp\pip-install-0cqjz8ka\pysatCDF\setup.py'"'"'; file='"'"'C:\Users\ASUS\AppData\Local\Temp\pip-install-0cqjz8ka\pysatCDF\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\ASUS\AppData\Local\Temp\pip-install-0cqjz8ka\pysatCDF\pip-egg-info'
cwd: C:\Users\ASUS\AppData\Local\Temp\pip-install-0cqjz8ka\pysatCDF
Complete output (5 lines):
Building CDF for pysatCDF.
running egg_info
running build_src
Cleaning CDF
error: [WinError 2] The system cannot find the file specified
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

please help me

Include kissat

The latest contest results are out, and we have a new top-solver: http://fmv.jku.at/kissat/

It's an improved version of CaDiCaL, and so hopefully not a big undertaking to include.

In a related note, we'll be shifting the nnf package to optionally use the pysat package for solving. Among other things, this will allow users to write arbitrary NNF formula, compile it using Tseitin, and then solve using pysat. The combination of the two libraries should hopefully address what you had in mind with the fourth bullet in the main TODO list.

Pass options to solver

I want to be able to set the random seed of the solver -- now I could add a special option for this, but it might be nicer to just be able to call parseOptions for every solver, maybe on construction of solver?

I was going to try this myself, but it would require turning a python string (or list of strings) into a C-like argv (so a list of strings, null terminated), and I'm not positive how to do that.

How to fix 'ERROR: Command errored out with exit status 1:'

I am trying to install pysat, but it keeps running error when building wheel for pysatCDF:

Requirement already satisfied: soupsieve>=1.2 in /anaconda3/lib/python3.7/site-packages (from beautifulsoup4->pysat) (1.8)
Building wheels for collected packages: pysatCDF
Building wheel for pysatCDF (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: //anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/tg/v1qsdkmn5rg_dnwh0k2xtw280000gn/T/pip-install-6ssrpcun/pysatCDF/setup.py'"'"'; file='"'"'/private/var/folders/tg/v1qsdkmn5rg_dnwh0k2xtw280000gn/T/pip-install-6ssrpcun/pysatCDF/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/tg/v1qsdkmn5rg_dnwh0k2xtw280000gn/T/pip-wheel-di7gnbw7
cwd: /private/var/folders/tg/v1qsdkmn5rg_dnwh0k2xtw280000gn/T/pip-install-6ssrpcun/pysatCDF/

How to set the Solver's verbosity?

Dear Pysat developer's team,

Thanks for creating such a useful toolkit. I want to solve a SAT problem encoded as a CNF. I am using the following commands to read the dimacs file containing the obtained CNF:

cnf_formula = formula.CNF(self.cnf_file_path)
sat_solver = solvers.Cadical()
sat_solver.append_formula(cnf_formula)
result = sat_solver.solve()

What is important for me is seeing the outputs generated by the chosen SAT solver, when it is solving the problem, since SAT solvers usually print out useful data, such as the amount of used time, and memory, and some other useful data related to the solving process. So, how can I set the verbosity parameter of a SAT solver to see more details of solving process? Thank you in advance for your help.

Kind regards,
Hosein

On the usage of assumptions and literals (set_phases)

Hello,

I would like to know if solving a formula with a list of
assumptions (code (1)) is semantically the same thing as using
set_phases with the same assumption literals (code (2)).

(1)

>>> s.solve(assumptions=[1, -2, 3])  # a SAT call with assumption literals

(2)

>>> s.set_phases(literals=[1, -2, 3])
>>> s.solve()

Thank you

Typo in WCNF class - unweighed vs unweighted

Good morning!

I've noticed a typo in the WCNF class.
The docs state that the function should be '''unweighted''', but in the source it is actually called '''unweighed'''

Could you please have a look at this?

Directly Support MAX-SAT in library

Recently I need to solve some combinatorial problem for my project. I discover your pysat and it is super convenient for solving SAT problems! One feature I'd like to see is to directly support some prebuilt MaxSAT algorithms in your library (I understand you provide them in your examples but it is not very user-friendly). Something like

>>> g = Glucose3()
>>> g.add_clause([-1, 2], weight=1)
>>> g.add_clause([-2, 3], weight=pysat.infinity)
>>> print g.solve(maxsat=pysat.FM)

ValueError: non-zero integer expected

I have created a model where the clauses are taken from a graph. The edge list of the graph is given below.

[[0, 1], [1, 0], [1, 2], [1, 3], [2, 1], [3, 1], [3, 4], [4, 3]]

I have used the following code to generate WCNF file.

from pysat.formula import WCNF
wcnf = WCNF()
for edge in edge_list:
    wcnf.append(edge)

The content of the generated WCNF file is given below.

p wcnf 4 8 1
1 0 1 0
1 1 0 0
1 1 2 0
1 1 3 0
1 2 1 0
1 3 1 0
1 3 4 0
1 4 3 0

When I try to solve it using the following code:

from pysat.examples.rc2 import RC2
with RC2(wcnf) as rc2:
    # solving the MaxSAT problem
    print(rc2.compute())
    print(rc2.cost)
    for model in rc2.enumerate():
        print(model, rc2.cost)

I see the following error.

ValueError                                Traceback (most recent call last)
<ipython-input-183-6c7ba2990b67> in <module>
      1 from pysat.examples.rc2 import RC2
----> 2 with RC2(wcnf) as rc2:
      3     # solving the MaxSAT problem
      4     print(rc2.compute())
      5     print(rc2.cost)

~/opt/anaconda3/envs/py38/lib/python3.8/site-packages/pysat/examples/rc2.py in __init__(self, formula, solver, adapt, exhaust, incr, minz, trim, verbose)
    222 
    223         # initialize SAT oracle with hard clauses only
--> 224         self.init(formula, incr=incr)
    225 
    226         # core minimization is going to be extremely expensive

~/opt/anaconda3/envs/py38/lib/python3.8/site-packages/pysat/examples/rc2.py in init(self, formula, incr)
    273 
    274         # creating a solver object
--> 275         self.oracle = Solver(name=self.solver, bootstrap_with=formula.hard,
    276                 incr=incr, use_timer=True)
    277 

~/opt/anaconda3/envs/py38/lib/python3.8/site-packages/pysat/solvers.py in __init__(self, name, bootstrap_with, use_timer, **kwargs)
    309 
    310         self.solver = None
--> 311         self.new(name, bootstrap_with, use_timer, **kwargs)
    312 
    313     def __enter__(self):

~/opt/anaconda3/envs/py38/lib/python3.8/site-packages/pysat/solvers.py in new(self, name, bootstrap_with, use_timer, **kwargs)
    348                 self.solver = Cadical(bootstrap_with, use_timer, **kwargs)
    349             elif name_ in SolverNames.glucose3:
--> 350                 self.solver = Glucose3(bootstrap_with, use_timer, **kwargs)
    351             elif name_ in SolverNames.glucose4:
    352                 self.solver = Glucose4(bootstrap_with, use_timer, **kwargs)

~/opt/anaconda3/envs/py38/lib/python3.8/site-packages/pysat/solvers.py in __init__(self, bootstrap_with, use_timer, incr, with_proof)
   1329         self.prfile = None
   1330 
-> 1331         self.new(bootstrap_with, use_timer, incr, with_proof)
   1332 
   1333     def __enter__(self):

~/opt/anaconda3/envs/py38/lib/python3.8/site-packages/pysat/solvers.py in new(self, bootstrap_with, use_timer, incr, with_proof)
   1362 
   1363                 for clause in bootstrap_with:
-> 1364                     self.add_clause(clause)
   1365 
   1366             self.use_timer = use_timer

~/opt/anaconda3/envs/py38/lib/python3.8/site-packages/pysat/solvers.py in add_clause(self, clause, no_return)
   1581 
   1582         if self.glucose:
-> 1583             res = pysolvers.glucose3_add_cl(self.glucose, clause)
   1584 
   1585             if res == False:

ValueError: non-zero integer expected


Cardinality for "all same"?

Hi,
I'd like to add a clause to a formula indicating that I want a series of values to be "all the same", either all TRUE or all FALSE.

How would one accomplish this?

pysat.card.CardEnc.atleast tries to set signal handler

I want to do all solver related work in it's own thread (to keep the GUI responsive).

This includes CNF creation (because it could have several million clauses).

But setting a signal handler only works in the main thread (and raises a ValueError exception in otzher threads).

Why does pysat.card.CardEnc.equals (encoding=pysat.card.EncType.sortnetwrk) (that ultimately calls atleast) needs to set the signal handler at all? It should just create some CNFclauses.

The simplest solution would probably be to have a try/except around the signal call that ignore the error.

Ctrl+C causes Python interpreter with pysat loaded to crash not gracefully yield an exception

Any time Ctrl+C is used to interrupt running code, it will throw a KeyboardInterrupt. But something is going on after doing SAT solving which causes it to not work all of the time and instead just exit the interpreter. Either this indicates Ctrl+C is being explicitly caught and inappropriately dealt with or some type of cleanup code is probably cause a crash.

Obviously important is that this is being run on Windows as Linux can have different behavior in this area as it uses a signal handling system which is a bit different. My event viewer clearly shows something is causing crashes and it never happens if I do not load pysat:

Faulting application name: python.exe, version: 3.8.2150.1013, time stamp: 0x5e55a7f0
Faulting module name: ntdll.dll, version: 10.0.18362.815, time stamp: 0xb29ecf52
Exception code: 0xc0000028
Fault offset: 0x00000000000fbf18
Faulting process id: 0x12448
Faulting application start time: 0x01d65234e08c1176
Faulting application path: C:\Program Files\Python38\python.exe
Faulting module path: C:\WINDOWS\SYSTEM32\ntdll.dll
Report Id: 75efd8f9-c92c-410e-9acc-a00aedd6f2b5
Faulting package full name: 
Faulting package-relative application ID: 

Since 0xc0000028 is a stack corruption issue, and everything else I am using is pure python, it implies that the compiled C code is responsible for this... Python 3.8 almost never crashes even under absurd memory load, etc.

I can attach a debugger and get a stack trace shortly as it will help narrow down which C code is the culprit.

  File "C:\Program Files\Python38\lib\site-packages\pysat\examples\lbx.py", line 287, in enumerate
    mcs = self.compute()
  File "C:\Program Files\Python38\lib\site-packages\pysat\examples\lbx.py", line 271, in compute
    self._compute()
  File "C:\Program Files\Python38\lib\site-packages\pysat\examples\lbx.py", line 390, in _compute
    self.do_cld_check(self.setd[i:])
  File "C:\Program Files\Python38\lib\site-packages\pysat\examples\lbx.py", line 441, in do_cld_check
    self._filter_satisfied(update_setd=True)
  File "C:\Program Files\Python38\lib\site-packages\pysat\examples\lbx.py", line 355, in _filter_satisfied
    if not self.satc[i]:
  File "C:\Program Files\Python38\lib\site-packages\pysat\examples\lbx.py", line 355, in _filter_satisfied
    if not self.satc[i]:
KeyboardInterrupt
The program '[76260] python.exe' has exited with code -1073741784 (0xc0000028).

This is not particularly helpful beyond showing it definitely is some type of memory mismanagement in the object deletion chain for LBX. Obviously something is not cleaning itself up properly and causing crashes.

package install error

compiling maplecm
c++ -std=c++11 -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -I.. -O3 -DNDEBUG -c core/Solver.cc -o core/Solver.o
core/Solver.cc: In member function ‘bool MapleCM::Solver::simplifyLearnt_core()’:
core/Solver.cc:549:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (nblevels < c.lbd()){
^
core/Solver.cc: In member function ‘bool MapleCM::Solver::simplifyLearnt_tier2()’:
core/Solver.cc:628:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (nblevels < c.lbd()){
^
core/Solver.cc: In member function ‘bool MapleCM::Solver::simplifyUsedOriginalClauses()’:
core/Solver.cc:734:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (nblevels < c.lbd()){
^
core/Solver.cc:687:12: warning: variable ‘avg’ set but not used [-Wunused-but-set-variable]
double avg;
^
core/Solver.cc: In member function ‘bool MapleCM::Solver::simplifyOriginalClauses()’:
core/Solver.cc:850:12: warning: variable ‘avg’ set but not used [-Wunused-but-set-variable]
double avg;
^
c++ -std=c++11 -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -I.. -O3 -DNDEBUG -c utils/Options.cc -o utils/Options.o
c++ -std=c++11 -fPIC -Wall -Wno-deprecated -fno-strict-aliasing -I.. -O3 -DNDEBUG -c utils/System.cc -o utils/System.o
preparing maplesat
error: <urlopen error [Errno 110] Connection timed out>

ERROR: Failed building wheel for python-sat
Running setup.py clean for python-sat
Building wheel for pypblib (setup.py) ... done
Created wheel for pypblib: filename=pypblib-0.0.4-cp35-cp35m-linux_x86_64.whl size=2396599 sha256=f6efe9002856681f8a69e9a1bc8fb7cd5560050d3c69fd4bc133b8e5f24b0c3e
Stored in directory: /tmp/pip-ephem-wheel-cache-5248gqqs/wheels/e2/92/98/d86282d693afed7b944be1ec76ff605de9ff93d1a51634e624
Building wheel for parsimonious (setup.py) ... done
Created wheel for parsimonious: filename=parsimonious-0.8.1-cp35-none-any.whl size=50875 sha256=ad7d3374b6325b8bf59fb74cef97b8733bb1f76d4c6597264e85d9bb81924e95
Stored in directory: /tmp/pip-ephem-wheel-cache-5248gqqs/wheels/b7/8d/e7/a0e74217da5caeb3c1c7689639b6d28ddbf9985b840bc96a9a
Building wheel for attr (setup.py) ... done
Created wheel for attr: filename=attr-0.3.1-cp35-none-any.whl size=3588 sha256=77ff4177f5f6c71f6391ab8492369a39d606dfda7ecc80707a5107adfc9f72d9
Stored in directory: /tmp/pip-ephem-wheel-cache-5248gqqs/wheels/f0/96/9b/1f8892a707d17095b5a6eab0275da9d39e68e03a26aee2e726
Successfully built pypblib parsimonious attr
Failed to build python-sat
Installing collected packages: parsimonious, bidict, funcy, toposort, attr, click, py-aiger, pypblib, python-sat
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/parsimonious'
Consider using the --user option or check the permissions.

I have tried many times. Every time it stuck on "preparing maplesat".

Constructor does not raise error when typo in parameters

The solver's constructor Solver does not raise any error in case of typo or parameters that does not even exist in the code. For instance:

s = Solver(boostrp_with=cnf.clauses)

works fine and the solver seems built. (Notice that I wrote bosstrp_with instead of `bootstrap_with').
It would be great if we are aware of such errors because we can work on an obsolete solver.

For example:

class test:
    def __init__(self, param1=None, param2=None):
        pass

we get an error from Python when:

>>> t = test(param3='string')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'param3'

Thank you.

Variable mapping when using from_aiger

Hi Alexey,

I want to convert an Aiger file with one Primary Output to CNF, and I found the from_aiger parameter in the CNF constructor. I wanted to know what mapping is used between the Primary Inputs, Latch Inputs of the Aiger file and variables of the CNF. I will need to modify the CNF later, for which I need to know the variables corresponding to the inputs and latches as well as the auxiliary vars.

Thanks!

Package Installing Issue

Hi! When I am installing the package from both pip and the GitHub version, I met such a problem:

gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/<PATH>/anaconda3/include -arch x86_64 -I/<PATH>/anaconda3/include -arch x86_64 -Icardenc -I/<PATH>/anaconda3/include/python3.7m -c cardenc/pycard.cc -o build/temp.macosx-10.7-x86_64-3.7/cardenc/pycard.o -std=c++11 -Wno-deprecated
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the
      command line to use the libc++ standard library instead
      [-Wstdlibcxx-not-found]
In file included from cardenc/pycard.cc:16:
In file included from cardenc/card.hh:11:
cardenc/bitwise.hh:11:10: fatal error: 'cmath' file not found
#include <cmath>
         ^~~~~~~
1 warning and 1 error generated.
error: command 'gcc' failed with exit status 1

Some solutions I have tried:

  1. I reinstalled the command line tool of Xcode by: xcode-select -p. I still cannot compile the code. I have tried to compile other c++ file with cmath library and it works fine.
  2. I changed the extra compile args in line 76 and 85 in setup.py from extra_compile_args=['-std=c++11', ...] to extra_compile_args=['-stdlib=libc++', ...]. This time it compiles but with many warnings:
    lglib.c:19486:7: warning: variable 'res' is used uninitialized whenever 'if'
     condition is false [-Wsometimes-uninitialized] 
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated] 
      solvers/pysolvers.cc:1142:20: warning: comparison of integers of different
      signs: 'int' and 'std::__1::vector<int, std::__1::allocator<int>
      >::size_type' (aka 'unsigned long') [-Wsign-compare]
        for (int i = 0; i < p.size(); ++i)

Is there any better solutions? How should I deal with the warnings?

Current working environment:
Python 3.7.1
System Version: macOS 10.14.2 (18C54)
Kernel Version: Darwin 18.2.0
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
using fish shell

Thank you so much!

CNF.nv is wrong

self.nv of pysat.formula.CNF, according to doc, should be the number of variables. It can be verified that:

from pysat.formula import CNF
assert CNF(from_clauses=[[1],[2]]).nv == 2

However, an error occurs here:

from pysat.card import CardEnc
assert CardEnc.equals([1,2],2).nv == 2  # failed

See screenshot:

image

Thanks!

`nof_clauses` on a solver does not update after `add_clause`

Issue in the title.
Here is an example of code (with comments):

from pysat.formula import CNF
from pysat.solvers import Solver, Glucose3

formula = CNF()
formula.append([-1, 2])

l = Solver(bootstrap_with=formula.clauses)
assert(l.nof_clauses() == 1) # OK
l.add_clause([1, 2])
assert(l.nof_clauses() == 2) # normal

l.add_clause([2])
### should fail
assert(l.nof_clauses() == 2) # 3 expected


################# second example

formula2 = CNF()
formula2.append([-1, 2])

l2 = Solver(bootstrap_with=formula2.clauses)
assert(l2.nof_clauses() == 1) # OK

l2.add_clause([2])
### should fail
assert(l2.nof_clauses() == 1) # 2 expected

Thanks for your help

Mentioning of OS-requirements as Windows won't do (following setup-docs)

There is no information at all in terms of OS and buildtools requirements. the setup-docs make the user think, that pip install python-sat will do, while patch, make and all those things are not available (and Visual Studio + those solvers is probably another problem). Even within anaconda including libmingw, i was not successful.

Please make somewhere clear, which exact requirements are assumed and which OS' are covered.

Cardinality constraints do not work with minicard

import pysat.solvers
import pysat.formula

cnfp=pysat.formula.CNFPlus()
cnfp.append(list(range(1, 10)))
cnfp.append([list(range(-9, -3)), 3], is_atmost=True)

with pysat.solvers.Solver("minicard") as solver:
    solver.append_formula(cnfp)
    solver.solve()
    model=solver.get_model()
    print(model)

Prints:

    [1, -2, -3, -4, -5, -6 ,-7, -8, -9]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.