Module logicng

Class PBConstraint

  • All Implemented Interfaces:
    Iterable<Formula>
    Direct Known Subclasses:
    CardinalityConstraint

    public class PBConstraint
    extends Formula
    A pseudo-Boolean constraint of the form c_1 * l_1 + ... + c_n * l_n R k where R is one of =, >, >=, <, <=.
    Since:
    1.0
    Version:
    2.3.2
    • Field Detail

      • literals

        protected final Literal[] literals
      • coefficients

        protected final int[] coefficients
      • comparator

        protected CType comparator
      • rhs

        protected int rhs
      • hashCode

        protected int hashCode
      • maxWeight

        protected int maxWeight
    • Method Detail

      • operands

        public Literal[] operands()
        Returns the literals of this constraint.
        Returns:
        the literals of this constraint
      • coefficients

        public int[] coefficients()
        Returns the coefficients of this constraint.
        Returns:
        the coefficients of this constraint
      • comparator

        public CType comparator()
        Returns the comparator of this constraint.
        Returns:
        the comparator of this constraint
      • rhs

        public int rhs()
        Returns the right-hand side of this constraint.
        Returns:
        the right-hand side of this constraint
      • isCC

        public boolean isCC()
        Returns true if this constraint is a cardinality constraint, false otherwise.
        Returns:
        true if this constraint is a cardinality constraint
      • isAmo

        public boolean isAmo()
        Returns true if this constraint is an at-most-one cardinality constraint, false otherwise.
        Returns:
        true if this constraint is an at-most-one cardinality constraint
      • isExo

        public boolean isExo()
        Returns true if this constraint is an exactly-one cardinality constraint, false otherwise.
        Returns:
        true if this constraint is an excatly-one cardinality constraint
      • maxWeight

        public int maxWeight()
        Returns the maximal coefficient of this constraint.
        Returns:
        the maximal coefficient of this constraint
      • normalize

        public Formula normalize()
        Normalizes this constraint s.t. it can be converted to CNF.
        Returns:
        the normalized constraint
      • numberOfOperands

        public int numberOfOperands()
        Description copied from class: Formula
        Returns the number of operands of this formula.
        Specified by:
        numberOfOperands in class Formula
        Returns:
        the number of operands of this formula
      • isConstantFormula

        public boolean isConstantFormula()
        Description copied from class: Formula
        Returns whether this formula is a constant formula ("True" or "False").
        Specified by:
        isConstantFormula in class Formula
        Returns:
        true if this formula is a constant formula, false otherwise
      • isAtomicFormula

        public boolean isAtomicFormula()
        Description copied from class: Formula
        Returns whether this formula is an atomic formula (constant, literal, pseudo Boolean constraint), or not.
        Specified by:
        isAtomicFormula in class Formula
        Returns:
        true if this formula is an atomic formula, false otherwise
      • containsVariable

        public boolean containsVariable​(Variable variable)
        Description copied from class: Formula
        Returns true if a given variable name is found in this formula, false otherwise.
        Specified by:
        containsVariable in class Formula
        Parameters:
        variable - the variable to search for
        Returns:
        true if a given variable is found in this formula
      • evaluate

        public boolean evaluate​(Assignment assignment)
        Description copied from class: Formula
        Evaluates this formula with a given assignment. A literal not covered by the assignment evaluates to false if it is positive, otherwise it evaluates to true.
        Specified by:
        evaluate in class Formula
        Parameters:
        assignment - the given assignment
        Returns:
        the result of the evaluation, true or false
      • restrict

        public Formula restrict​(Assignment assignment)
        Description copied from class: Formula
        Restricts this formula with a given assignment.
        Specified by:
        restrict in class Formula
        Parameters:
        assignment - the given assignment
        Returns:
        a new restricted formula
      • containsNode

        public boolean containsNode​(Formula formula)
        Description copied from class: Formula
        Returns true if this formula contains a given node, false otherwise.

        In particular, a Literal node ~a does NOT contain the node a.

        Specified by:
        containsNode in class Formula
        Parameters:
        formula - the node
        Returns:
        true if this formula contains a given node
      • substitute

        public Formula substitute​(Substitution substitution)
        Description copied from class: Formula
        Performs a given substitution on this formula.
        Specified by:
        substitute in class Formula
        Parameters:
        substitution - the substitution
        Returns:
        a new substituted formula
      • negate

        public Formula negate()
        Description copied from class: Formula
        Returns a negated copy of this formula.
        Specified by:
        negate in class Formula
        Returns:
        a negated copy of this formula
      • getEncoding

        public List<Formula> getEncoding()
        Encodes this constraint as CNF and stores the result, if the encoding does not already exist.
        Returns:
        the encoding
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • stream

        public Stream<Formula> stream()
        Description copied from class: Formula
        Returns a stream of this formula's operands.

        Most times streams have worse performance then iterating over the formula per iterator. Since internally formulas store their operands, a costly call to Arrays.stream() is necessary. So if performance matters - avoid using streams.

        Specified by:
        stream in class Formula
        Returns:
        the stream