Does anyone know of a good program to convert CNF files with any number of variables per clause to CNF files with exactly 3 variables per clause (3-CNF)? I've seen this algorithm in computer science books but can't find an implementation anywhere and would hate to waste time implementing it myself if others have already done it. Thanks!
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- How to get a fixed number of evenly spaced points
- Space complexity of validation of a binary search
相关文章
- What are the problems associated to Best First Sea
- Coin change DP solution to keep track of coins
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Algorithm for maximizing coverage of rectangular a
- How to measure complexity of a string?
- Select unique/deduplication in SSE/AVX
- How to smooth the blocks of a 3D voxel world?
I didn't know any program to do that either, but the algorithm is really simple so just I wrote the following python script (download) that reads a general CNF in DIMACS format and writes the CNF of an equivalent 3-SAT problem in DIMACS format:
The interesting bit is of course the
for clause in cnf:
loop that takes the general sat problem stored incnf
and transforms it into a 3-sat instance stored innew_cnf
. It does this by translating a clause such asinto the following set of clauses.
The first three clauses are added to
new_cnf
. The last clause is not 3-sat so the algorithm is re-run on this last clause, yielding the following new clauses:This are all 3-sat clauses, so they are added to
new_cnf
and the algorithm continues with the next clause fromcnf
. (If the last clause were not 3-sat, the algorithm would keep working on it until only 3-sat clauses are left. The length of the last clause approximately halves with each iteration.)SAT is not solvable in polynomial time (according to the current knowledge). 2-SAT is solvable in polynomial time.
So a conversion from generic SAT to 2-SAT will not be fast (not in polynomial time), otherwise we would find a polynomial-time algorithm for SAT.
In other words, the time needed to convert SAT to 2-SAT is roughly the same as the time to just solve SAT.
Maybe you mean 3-SAT, not 2-SAT?