public class Clause extends Object
A clause is a list of integers different from 0. A clause is to be interpreted as the disjunction of the literals that are represented by the integer values. In DIMACS, literals are represented by integers. Positive numbers 1,2,... represent the first, second, ... propositional variable. Negative numbers -1,-2, ... represent the negation of the first, second, ... variable. For instance, the formula (¬A ∨ B) ∧ (C ∨ ¬B) can be represented as the two clauses {-1, 2} and {3, -2}.
concat(int)
or concat(Clause)
which result in new clauses without changing the receiver of the method call.Constructor and Description |
---|
Clause(int... literals)
Instantiates a new clause from a list of literals.
|
Clause(int[] array,
int start,
int len)
Instantiates a new clause from a segment of an integer array
|
Modifier and Type | Method and Description |
---|---|
Clause |
concat(Clause clause)
Get a clause that represents this clause augmented by the literals of the
argument.
|
Clause |
concat(int literal)
Get a clause that represents this clause augmented by an additional
literal.
|
int |
getMaxVar()
Get the largest index of all literals in the clause.
|
int |
getVariable(int var) |
int[] |
toArray()
Extract the integer values of this clause into an array.
|
String |
toDIMACS()
Translate the clause to DIMACS text representation.
|
String |
toString()
A clause is textually represented as a list in curly braces.
|
public Clause(int... literals) throws IllegalArgumentException
literals
- a list of zero or more literal integers (different from 0)IllegalArgumentException
- iff the list of literals contains the value 0.public Clause(int[] array, int start, int len) throws IndexOutOfBoundsException, IllegalArgumentException, NullPointerException
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 Clause concat(int literal) throws IllegalArgumentException
literal
- the additional literalliteral
.IllegalArgumentException
- if the arguments is 0public Clause concat(Clause clause)
clause
- the additional literalsclause
.public String toString()
For example: The expression new Clause(-1,2,2).toString() yields {-1,2,2}.
public String toDIMACS()
In DIMACS text representation literals are separated by space characters and clauses terminated by a single 0.
For example: The expression new Clause(-1,2,2).toDIMACS() yields -1 2 2 0.
public int[] toArray()
For example: The expression Clause.make(-1,2,2).toArray() yields [-1,2,2]. The result is freshly created. You may safely change it.
public int getMaxVar()
The index of a literal is the used variable number, i.e. the absolute value.
For example: The expression new Clause(-1,2,2).getMaxVar() yields 2. The expression new Clause(5,-7).getMaxVar() yields 7.
public int getVariable(int var) throws IllegalArgumentException
IllegalArgumentException