Closed ElisabettaV4t1qbit closed 9 months ago
@ElisabettaV4t1qbit, thanks for reporting. At this stage, I can't confirm the issue because formula parsing works fine on my machines. Can you upload your formula so that I see what fails and why?
Thank you for your answer.
I added to my PR the file example_problem.cnf
that generates the error I reported above by running:
from pysat.formula import CNF
formula = CNF(from_file="example_problem.cnf")
I have MacOS Ventura 13.5.2, and I am installing python-sat in a virtual environment based on python 3.9.1. Please let me know if you need further information.
Thank you, I have checked the file, @ElisabettaV4t1qbit. It does not seem to respect the format, i.e. it is not surprising that the parser fails.
Are you referring to the last 2 lines in my file?
%
0
After I removed them, the last versions of the package (python-sat==0.1.8.dev9
) actually worked. But those lines are present in almost all the instances of one of the most famous and used (to the best of my knowledge) SAT problems library: SATLIB - Benchmark problems.
Wouldn't be better if the code allowed more flexibility in the formula format?
Well, as far as I can see (I've manually checked a number of benchmark families available there), you are talking about uf* benchmarks only. According to the description, they were generated in 1991, i.e. before the format was proposed (it dates back to 1993). To be honest, I am not entirely convinced that it is better and simpler to support files in a wrong format rather than update the affected files.
@ElisabettaV4t1qbit, here is a trivial Perl script that fixes the issue in the files (a Python equivalent is also straightforward):
#!/usr/bin/env perl
while(<>) {
if (m/^c/) { print; }
elsif (m/\%/) { last; }
else { print; }
}
As I mentioned above, I do believe it is a much better practice to fix CNF instances written in a wrong format rather than update the toolkit to support those incorrect formulas.
Thank you very much for you suggestion!
I am a first-timer to SAT problems, and ran into exact same issue with that same dataset. Thank you for clarifying and documenting it here!
Since version
0.1.7.dev21
, reading a formula usingpysat.formula.CNF(from_file=<file name>)
produces the following error: