Record Class BinaryClause
java.lang.Object
java.lang.Record
org.ddolib.examples.layered.max2sat.BinaryClause
- Record Components:
i- the first literal of the clausej- the second literal of the clause
- All Implemented Interfaces:
Comparable<BinaryClause>
Class to model a Binary clause of two literals for CNF formula.
To symbolize a literal x_i , for i > 0, we give the value i as input.
To symbolize NOT x_i, we give -i.
-
Constructor Summary
ConstructorsConstructorDescriptionBinaryClause(int i, int j) Creates a new binary clause, checking that neither literal is0. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(BinaryClause other) Used to compare binary clauses.booleanIndicates whether some other object is "equal to" this one.inteval(int a, int b) Evaluates if the clause is verified given 2 boolean values.final inthashCode()Returns a hash code value for this object.inti()Returns the value of theirecord component.intj()Returns the value of thejrecord component.toString()Returns a string representation of this record class.
-
Constructor Details
-
BinaryClause
public BinaryClause(int i, int j) Creates a new binary clause, checking that neither literal is0.
-
-
Method Details
-
eval
public int eval(int a, int b) Evaluates if the clause is verified given 2 boolean values.- Parameters:
a- the value to attribute to the variablex_i(0 or 1)b- the value to attribute to the variablex_j(0 or 1)- Returns:
- 1 if the clause is verified, 0 otherwise
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
compareTo
Used to compare binary clauses. It is used to sort them when generating Max2Sat instances.
The induced order is the following:- The lexical order on the literals' indices.
- The positive literal before the negative ones.
- Specified by:
compareToin interfaceComparable<BinaryClause>- Parameters:
other- the binary clause to be compared- Returns:
0if ifthis == other1ifthis > other-1ifthis < other
-
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
i
public int i()Returns the value of theirecord component.- Returns:
- the value of the
irecord component
-
j
public int j()Returns the value of thejrecord component.- Returns:
- the value of the
jrecord component
-