public class SATSolver extends Object
Internally, the class 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();
You can choose the SAT solver to be used by configuring the solver:
System property | Static variable | Description | Default |
---|---|---|---|
spotlight.minisat | USE_MINISAT |
switch between SAT4J and MiniSat | false |
spotlight.minisat.keep | MINISAT_KEEP |
for debug: keep the input/output files from minisat. Their location is printed to the terminal. | false |
spotlight.minisat.executable | MINISAT_EXECUTABLE |
If the MiniSat executable is not your search path for executables, you can specify its absolute location here | "minisat" |
Clause
Modifier and Type | Field and Description |
---|---|
static String |
MINISAT_EXECUTABLE
If the MiniSat executable is not your search path for executables, you
can specify its absolute location here.
|
static boolean |
MINISAT_KEEP
for debug: keep the input/output files from minisat.
|
static boolean |
USE_MINISAT
switch between sat4j and minisat.
|
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.
|
void |
addClause(int[] array,
int start,
int len)
Add a single clause constructed from a part of an array 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 static final boolean USE_MINISAT
true
means minisat,
false
means sat4j.public static final boolean MINISAT_KEEP
public static final String MINISAT_EXECUTABLE
public void addClause(int... literals)
The list of arguments is treated as a single clause and added to solver.
literals
- a list of zero or more literal values.IllegalArgumentException
- if a literal is 0.public void addClause(int[] array, int start, int len)
The system constructs a clause from the argument array beginning at index start, taking len many values.
array
- the non-null array to take the literals fromstart
- the first index in array to take literals fromlen
- the number of literals to take from the arrayIndexOutOfBoundsException
- if start
is outside the array index range or if
start+len
is outside.IllegalArgumentException
- if 0 is contained in the array or if len < 0
.NullPointerException
- if array is null
public void addClause(Clause clause)
clause
- a non-null reference to a clause.NullPointerException
- if the argument is null
.public List<Clause> getClauses()
The returned reference cannot be modified but keeps track of changes to the solver.
public int getMaximumVariable()
For example, the empty solver would return 0. After adding the clause {-1,5} it would return 5. After adding {-7,6} it returns 7.
public int[] solve() throws SpotlightException
The clauses remain in the solver and will be sent again if this method is invoked a second time.
If set of clauses has no satisfying assignment (UNSAT), 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.
SpotlightException
- if any exception was raised during the satsolving process.