Record Class BinaryClause

java.lang.Object
java.lang.Record
org.ddolib.examples.layered.max2sat.BinaryClause
Record Components:
i - the first literal of the clause
j - the second literal of the clause
All Implemented Interfaces:
Comparable<BinaryClause>

public record BinaryClause(int i, int j) extends Record implements 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

    Constructors
    Constructor
    Description
    BinaryClause(int i, int j)
    Creates a new binary clause, checking that neither literal is 0.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Used to compare binary clauses.
    boolean
    Indicates whether some other object is "equal to" this one.
    int
    eval(int a, int b)
    Evaluates if the clause is verified given 2 boolean values.
    final int
    Returns a hash code value for this object.
    int
    i()
    Returns the value of the i record component.
    int
    j()
    Returns the value of the j record component.
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BinaryClause

      public BinaryClause(int i, int j)
      Creates a new binary clause, checking that neither literal is 0.
  • 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 variable x_i (0 or 1)
      b - the value to attribute to the variable x_j (0 or 1)
      Returns:
      1 if the clause is verified, 0 otherwise
    • equals

      public boolean equals(Object obj)
      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 '=='.
      Specified by:
      equals in class Record
      Parameters:
      obj - the object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • compareTo

      public int compareTo(BinaryClause other)
      Used to compare binary clauses. It is used to sort them when generating Max2Sat instances.
      The induced order is the following:
      1. The lexical order on the literals' indices.
      2. The positive literal before the negative ones.
      Specified by:
      compareTo in interface Comparable<BinaryClause>
      Parameters:
      other - the binary clause to be compared
      Returns:
      • 0 if if this == other
      • 1 if this > other
      • -1 if this < 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • i

      public int i()
      Returns the value of the i record component.
      Returns:
      the value of the i record component
    • j

      public int j()
      Returns the value of the j record component.
      Returns:
      the value of the j record component