
Modern SAT solvers: fast, neat and underused - kachnuv_ocasek
https://codingnest.com/modern-sat-solvers-fast-neat-and-underused-part-3-of-n/
======
OskarS
What would be a concrete problem you could solve with SAT solvers, besides the
obvious "satisfy this boolean expression" (which doesn't exactly come up every
day)? Is it a useful tool for other NP-complete problems?

I mean, certainly you COULD reduce the Traveling Salesman Problem to SAT (it's
NP-complete, after all), but I would assume that it would be a totally
impractical way of doing it compared to more specialized algorithms.

I'm asking since the title contains the word "underused", but doesn't
elaborate on practical use-cases. What would you use it for?

~~~
sudhirj
I’ve had a supply demand problem that I couldn’t figure out how to use a SAT
solver for - thousands of demands ( movies have to reach thousands of
theatres) with tens of possible paths (fedex, satellite, download) - each at
different costs, some impossible and costs will change with volume and
consideration of other similar deliveries. Have a solution that models each
choice of supply demand tuples as nodes in a tree and doing depth first search
on it.

Any ideas on how to switch to an SAT solver? How would I even write such a
large SAT Boolean expression, and how would I tell the SAT solver that the
costs will change for each choice depending on business rules and other
choices made? It seemed impossible with a SAT system but I assume I’m not
familiar enough with the concepts.

~~~
darzu
You probably want to use SMT (which uses SAT underneath), not SAT directly.
SMT solvers usually let you write constraints over numbers which is a more
natural fit for your problem.

Also if you have thousands of variables, you probably shouldn't be writing SMT
statements directly. Usually you have some sort of script for your problem
domain that emits SMT then invokes the solver. E.g. the popular SMT solver Z3
has a very simple lisp-like syntax that's easy to emit from a script.

As for changing costs, you might be able to use simple expressions like:
costOfShippingXusingZ = 100 - numOfXusingZ * 2

Or you might use "soft constraints" that let you add weights to optional
constraints.

It's important to note that with SMT/SAT solvers you generally want to keep
your formulas linear or "first-order" which means don't multiply variables
together if you can help it.

This might be useful:
[https://rise4fun.com/Z3/tutorial/optimization](https://rise4fun.com/Z3/tutorial/optimization)

~~~
sigstoat
> Also if you have thousands of variables, you probably shouldn't be writing
> SMT statements directly. Usually you have some sort of script for your
> problem domain that emits SMT then invokes the solver. E.g. the popular SMT
> solver Z3 has a very simple lisp-like syntax that's easy to emit from a
> script.

the follow on is that the same program should also process the model (answer)
that Z3 produces and render it in a domain-appropriate fashion.

this is easiest if you use something like the python interface to Z3, instead
of actually generating SMT-LIB sexps and feeding them to Z3.

------
pdobsan
The article does not mention it but "symmetry breaking", a technique of
exploiting symmetry to prune the search tree, can also be an important
component of modern SAT solvers. In some sense one cannot do better than
avoiding all symmetries in the given problem however that might come at
significant computational price in practice.

Static symmetry breaking is performed as a kind of preprocessing, while
dynamic symmetry breaking is interleaved with the search process. The static
method has been used more but there are promising attempts to use dynamic
symmetry breaking with CDCL solvers. See, for example, cosy
([https://github.com/lip6/cosy](https://github.com/lip6/cosy)) a symmetry
breaking library which can be used with CDCL solvers.

~~~
rienko
I’ve researched many moon ago, breaking symmetries dynamically by adding
clause conflicts. You take the search space build a graph with it and pass it
to a Graph homomorphism detector. Then you create adicional clauses that break
the symmetry by stopping possible assignments that limit the search space. The
overhead of searching for symmetries and the exposition of dynamic clauses,
make it a difficult trade off against the ruthless efficiency of traditional
CDCL. Also many competitions used to occur every year to find out the fastest
solver, these things have been optimized far beyond you would do for “normal”
software.

~~~
pdobsan
> The overhead of searching for symmetries and the exposition of dynamic
> clauses, make it a difficult trade off against the ruthless efficiency of
> traditional CDCL

That is certainly true. However, once all the other components have been
optimized the hell out of them (of course that is a never ending story itself
but probably with diminishing returns) the optimization of the symmetry
breaking parts will follow. As I mentioned before, efficiently dealing with
isomorphism in the search space is the ultimate (theoretical) optimization.

This development can already been observed looking at the history of graph
automorphism packages. For a very long time "naughty" was the only significant
player than suddenly came "saucy" and "bliss". As far as I know, one of the
motivations for the newcomers was to use them for symmetry breaking.

------
thijsvandien
At this year's PyCon, Raymond Hettinger gave a talk about the very subject:
[https://www.youtube.com/watch?v=_GP9OpZPUYc](https://www.youtube.com/watch?v=_GP9OpZPUYc).
I haven't watched it yet, but knowing him, it will definitely be worth doing
so.

~~~
gloflo
It is! He ran out of time a bit I think, at least it felt quite rushed at
times, but I was left very curious and motivated to try some SAT.

------
bayesian_horse
I think the number one reason SAT Solvers are underutilized is because even
relatively advanced programmers like me don't have a particular clue how to
frame their problems for a SAT solver.

------
projectramo
Although modern SAT solvers has a ring to it, I wish we would go back to
calling them high schoolers.

~~~
Wistar
Yes. Isn't this what has Felicity Huffman is facing a prison sentence?

------
flatfilefan
Can anyone help with what looks like SAT scalability problem? Is there a
modern SAT solver that can do it? I was trying out Google SAT and it seems not
to be able to scale to a simple school scheduling problem. Here’s the post
with the code and test data [https://groups.google.com/forum/m/#!topic/or-
tools-discuss/O...](https://groups.google.com/forum/m/#!topic/or-tools-
discuss/O8LZ9n__LVA)

~~~
maweki
In the worst case we can't get around exponential runtime in the problem size.
This is problematic since encoding often is not even linear but quadratic or
worse. But there are often tricks to get to encoding to nlogn size.

Problems that are "hard" are usually specially crafted (SAT competition).

Getting back to your question: In practice most problems do not show
exponential runtime behaviour. Using a good SAT solver is key here since the
more naive an implementation is, the more probable it is to run into
exponential runtime with practical problems.

~~~
flatfilefan
Thanks. Is there such a good SAT solver you would recommend to try out?

------
calf
Is there a standard book or lecture that explains the stuff like conflict
clauses and literal watch? I see informal tutorials but something more fully
explained, but not overly technical would be useful for people interested in
applications. Just something in between blog posts and having to read the
original technical papers.

~~~
bayesian_horse
The barrier to entry seems extremely high. Most "example" problems already
require arcane domain knowledge.

------
ar_xiv
okay, I'll bite.. what's a SAT, and why does it need to be solved? Am I a
buffoon for thinking it's the standardized test?

~~~
mlevental
hmm I wonder if the article about SAT solvers defines them?
[https://codingnest.com/modern-sat-solvers-fast-neat-
underuse...](https://codingnest.com/modern-sat-solvers-fast-neat-underused-
part-1-of-n/)

~~~
city41
To be fair it took me a bit realize this was part 3 of a series. It would have
made more sense to post part 1 to HN.

------
anjc
Why are people ITT talking about reducing problems to SAT? As I understand it,
the point of reducing a problem to SAT is because there's a proof that SAT is
NP-Complete which in turn would prove that your problem is NP-Complete. But if
you have some sort of industrial constraint
satisfaction/ASP/scheduling/search/etc problem, you can solve it with whatever
methods are available. You don't have to reduce a problem in such and such
domain down to a big Boolean formula and solve it via SAT techniques. Am I
wrong?

~~~
ausbah
Reading through a couple of other responses in this thread, it seems that
converting a problem to be compatible with a SAT solver can sometimes result
in unexpected gains in speed? That SAT solvers can sometimes be a better
solution to a problem than the general "go to" solutions for a domain, despite
it seeming to be inapplicable to such a domain? Maybe?

~~~
taejo
It's not that they seem inapplicable to some domain: they're applicable to a
huge number of domains (basically any kind of constraint satisfaction
problem). A lot of people thinks that this generality means that solving SAT
problems is difficult, but in reality it means that a huge amount of effort
has been invested into SAT solvers, which may outweigh the benefits you can
get from a specialized solver.

------
trombonechamp
What is the benefit of using a SAT solver directly instead of an SMT solver,
other than tweaking for a bit better performance in the SAT solver?

------
lou1306
Since I cannot find it mentioned in the OP nor in the comments: if you want to
experiment with SAT, the pysat package might be a pretty good start.

[https://github.com/pysathq/pysat](https://github.com/pysathq/pysat)

The API is not exactly Pythonic (numpy/scipy/opencv style) but it's loaded
with features.

------
tantalor
"and underused"

Where does the article talk about this?

------
gajomi
Stupid question... Are there equivalent (in the sense of being fast and having
nice interfaces) solvers for #SAT problems? A whole pile of inference in
machine learning can be framed in this way which makes me curious.

~~~
hugomg
In case others aren't familiar with the termiology: #SAT is the counting
version of the SAT problem, which tries to find how many different solutions
exist to a set of constraints)

~~~
rcfox
How similar is that to answer set programming?

------
anjc
Is meta-learning still useful for SAT solving (e.g SATzilla)?

------
IloveHN84
I thought it was an article on satellite signal for tv

