Module logicng

Class EvaluatesToConstantPredicate

  • All Implemented Interfaces:
    FormulaPredicate

    public final class EvaluatesToConstantPredicate
    extends Object
    implements FormulaPredicate
    Checks if the given formula is evaluated to false/true for a given (partial) assignment.

    Note: If a partial assignment is given, the check only recognizes simple unsatisfiable/tautology cases

    • operand of an AND/OR is false/true
    • all operators of an OR/AND are false/true
    • AND/OR has two operands with complementary negations
    This evaluation differs from the standard formula evaluation Formula.evaluate(Assignment) in two ways. It accepts partial assignments, and it tries to avoid the generation of intermediate formula by the formula factory objects in order to speed up the performance.

    Example 01: When evaluation to false the formula (a | b) & (~a | c) with partial assignment [b -> false, c -> false] yields to a & ~a which is recognized as unsatisfiable.

    Example 02: When evaluation to true the formula (a & b) | (~a & c) with partial assignment [b -> false, c -> false] yields to a | ~a which is recognized as a tautology.

    Since:
    2.0.0
    Version:
    2.0.0
    • Constructor Detail

      • EvaluatesToConstantPredicate

        public EvaluatesToConstantPredicate​(boolean evaluatesToTrue,
                                            Map<Variable,​Boolean> mapping)
        Constructs a new evaluation predicate.
        Parameters:
        evaluatesToTrue - false if the check aims for true, false if the check aims for false
        mapping - the (partial) assignment
    • Method Detail

      • getMapping

        public Map<Variable,​Boolean> getMapping()
        Returns the (partial) assignment.
        Returns:
        the (partial) assignment
      • test

        public boolean test​(Formula formula,
                            boolean caching)
        Checks if the formula evaluates to false (or true) when the (partial) assignment is applied.
        Specified by:
        test in interface FormulaPredicate
        Parameters:
        formula - the formula
        caching - indicator for caching (currently not used)
        Returns:
        true if applying the (partial) assignment yields to the specified constant, otherwise false