public class SATSolver extends Object
Clause
is used to store clauses.
SATSolver solver = new SATSolver(); // adding DIMACS clauses solver.addClause(42, -23, 7); // ... // trigger invocation of the underlying solver int[] result = solver.solve();
Clause
Constructor and Description |
---|
SATSolver() |
Modifier and Type | Method and Description |
---|---|
void |
addClause(Clause clause)
Add a single clause to the solver.
|
void |
addClause(int... literals)
Add a single clause to the solver.
|
List<Clause> |
getClauses()
Get the list of all clauses added to the solver.
|
int |
getMaximumVariable()
Get the highest variable index amongst all clauses in the solver.
|
int[] |
solve()
Invoke the SAT solver and return a satisfying variable assignment if one
has been found.
|
public void addClause(int... literals)
literals
- a list of zero or more literal values.IllegalArgumentException
- if a literal is 0.public void addClause(Clause clause)
clause
- a non-null reference to a clause.NullPointerException
- if the argument is null
.public List<Clause> getClauses()
public int getMaximumVariable()
public int[] solve() throws org.sat4j.specs.TimeoutException
null
is returned. Otherwise a variable assignment is returned. This array
contains literals for the variables between 1 and
getMaximumVariable()
. Every variable appears either positive or
negative. The clause set is satisfied if variable with positive
occurrence are set to true and the others to false.
MiniSat and sat4j are supported. See the top of the page on how to change
the used sat solver.LightsFormatException
- if any exception was raised during the satsolving process.org.sat4j.specs.TimeoutException