|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectCnf
public class Cnf
This class provides a representation of a CNF, including methods for constructing the CNF, for converting it into an array of arrays of Literals, and for printing. The class also includes a number of static methods which may be useful in processing CNF formulas.
In most cases, a complete CNF can be created using the constructor (which constructs an empty CNF), and the methods addClause() (which adds a clause to the CNF), and addLiteral() (which adds a literal to one of the clauses, by default, the last clause). Other methods are provided for accessing or setting individual literals of individual clauses, and for removing literals or entire clauses.
Each clause has an index as in an array, the first having index 0, the next with index 1, etc. Similarly, within each clause, every literal has an index according to the order in which it was added. Clauses and literals can be accessed using these indices. In addition, the method toLiteralArray() returns an array of arrays of Literals containing all of the elements of the CNF in the correct order according to this indexing.
A literal is generally specified by a sign and a symbol. The sign is represented by a boolean which is false if the literal is negated, and true otherwise. Each symbol is given by an arbitrary String, and two such symbols are considered the same if and only if the corresponding Strings are equal. However, the components of the array of arrays returned by toLiteralArray() represent each symbol by its index, i.e., by an integer between 0 and getNumSymbols() - 1. The String corresponding to such an index can be accessed using the getSymbolName() method.
Constructor Summary | |
---|---|
Cnf()
This is the constructor for the class. |
Method Summary | |
---|---|
void |
addClause()
Adds a new clause to this CNF. |
void |
addLiteral(int clause,
java.lang.String symbol,
boolean sign)
Adds a new literal to a specified clause of this CNF. |
void |
addLiteral(java.lang.String symbol,
boolean sign)
Adds a new literal to the last clause that was added to the CNF. |
int |
getClauseLength(int clause)
Returns the number of literals in the specified clause of this CNF. |
int |
getNumClauses()
Returns the number of clauses in this CNF. |
int |
getNumSymbols()
Returns the number of unique symbols appearing in literals that have been added to this CNF. |
boolean |
getSign(int clause,
int index)
Returns the sign for the literal in the specified position of this CNF. |
java.lang.String |
getSymbol(int clause,
int index)
Returns the symbol for the literal in the specified position of this CNF. |
java.lang.String |
getSymbolName(int index)
Returns the name (as a String) of the symbol with the given index. |
static boolean |
isClauseSat(Literal[] clause,
boolean[] model)
Returns true if the given model satisfies the given clause. |
static int |
numClauseUnsat(Literal[][] cnf,
boolean[] model)
Returns the number of clauses of the given CNF not satisfied by the given model. |
void |
print()
Prints this CNF to standard output. |
void |
printModel(boolean[] model)
Prints a given model to standard output. |
void |
removeClause(int clause)
Removes the entire specified clause from this CNF. |
void |
removeLiteral(int clause,
int index)
Removes the specified literal from the specified clause from this CNF. |
static void |
runSat(Generator generator,
SatSolver sat_solver,
int num_reps,
int time_limit)
Repeatedly calls a given sat-solver on CNF's generated by the given generator. |
void |
setLiteral(int clause,
int index,
java.lang.String symbol,
boolean sign)
Replaces the literal in the specified position of this CNF. |
Literal[][] |
toLiteralArray()
Returns this CNF represented as an array of arrays of Literals. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Cnf()
Method Detail |
---|
public void addClause()
public void addLiteral(java.lang.String symbol, boolean sign)
symbol
- the symbol of the new literal, as a Stringsign
- the sign of the new literal
java.util.NoSuchElementException
- if CNF is emptypublic void addLiteral(int clause, java.lang.String symbol, boolean sign)
clause
- index of clause to which literal is to be addedsymbol
- the symbol of the new literal, as a Stringsign
- the sign of the new literal
java.lang.ArrayIndexOutOfBoundsException
- if clause index is out of rangepublic int getNumSymbols()
public int getNumClauses()
public int getClauseLength(int clause)
clause
- index of specified clause
java.lang.ArrayIndexOutOfBoundsException
- if clause index is out of rangepublic java.lang.String getSymbol(int clause, int index)
clause
- index of specified clauseindex
- index of specified literal within that clause
java.lang.ArrayIndexOutOfBoundsException
- if either index is out of rangepublic boolean getSign(int clause, int index)
clause
- index of specified clauseindex
- index of specified literal within that clause
java.lang.ArrayIndexOutOfBoundsException
- if either index is out of rangepublic void setLiteral(int clause, int index, java.lang.String symbol, boolean sign)
clause
- index of specified clauseindex
- index of specified literal within that clausesymbol
- the symbol of the new literal, as a Stringsign
- the sign of the new literal
java.lang.ArrayIndexOutOfBoundsException
- if either index is out of rangepublic void removeClause(int clause)
clause
- index of specified clause
java.lang.ArrayIndexOutOfBoundsException
- if clause index is out of rangepublic void removeLiteral(int clause, int index)
clause
- index of specified clause
java.lang.ArrayIndexOutOfBoundsException
- if either index is out of rangepublic java.lang.String getSymbolName(int index)
index
- index of specified symbol
java.lang.IndexOutOfBoundsException
- if index is out of rangepublic Literal[][] toLiteralArray()
public void print()
public void printModel(boolean[] model)
public static void runSat(Generator generator, SatSolver sat_solver, int num_reps, int time_limit)
public static boolean isClauseSat(Literal[] clause, boolean[] model)
public static int numClauseUnsat(Literal[][] cnf, boolean[] model)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |