Module logicng

Class Assignment


  • public final class Assignment
    extends Object
    A Boolean assignment.

    Note: the internal data structure is a plain list - no checking of the model is performed e.g. if contradictory literals are added. Since assignments are used e.g. in the model enumeration of the SAT solvers these checks would be too costly.

    Since:
    1.0
    Version:
    2.3.1
    • Constructor Detail

      • Assignment

        public Assignment()
        Constructs a new empty assignment (without fast evaluation).
      • Assignment

        public Assignment​(boolean fastEvaluable)
        Constructs a new empty assignment.
        Parameters:
        fastEvaluable - indicates whether this assignment should be evaluable fast. If this parameter is set to true the internal data structures will be optimized for fast evaluation but creation of the object or adding literals can take longer.
      • Assignment

        public Assignment​(Collection<? extends Literal> lits)
        Constructs a new assignment for a given collection of literals (without fast evaluation).
        Parameters:
        lits - a new assignment for a given collection of literals
      • Assignment

        public Assignment​(Literal... lits)
        Constructs a new assignment for a given array of literals (without fast evaluation).
        Parameters:
        lits - a new assignment for a given array of literals
      • Assignment

        public Assignment​(Collection<? extends Literal> lits,
                          boolean fastEvaluable)
        Constructs a new assignment for a given collection of literals.
        Parameters:
        lits - a new assignment for a given collection of literals
        fastEvaluable - indicates whether this assignment should be evaluable fast. If this parameter is set to true the internal data structures will be optimized for fast evaluation but creation of the object or adding literals can take longer.
      • Assignment

        public Assignment​(Literal lit)
        Constructs a new assignment with a single literal assignment (without fast evaluation).
        Parameters:
        lit - the literal
      • Assignment

        public Assignment​(Literal lit,
                          boolean fastEvaluable)
        Constructs a new assignment with a single literal assignment.
        Parameters:
        lit - the literal
        fastEvaluable - indicates whether this assignment should be evaluable fast. If this parameter is set to true the internal data structures will be optimized for fast evaluation but creation of the object or adding literals can take longer.
    • Method Detail

      • convertToFastEvaluable

        public void convertToFastEvaluable()
        Converts this assignment to a fast evaluable assignment.
      • fastEvaluable

        public boolean fastEvaluable()
        Returns whether this assignment is fast evaluable or not.
        Returns:
        true if this assignment is fast evaluable, false otherwise
      • size

        public int size()
        Returns the number of literals in this assignment.
        Returns:
        the number of literals in this assignment
      • positiveVariables

        public List<Variable> positiveVariables()
        Returns the positive literals of this assignment as variables.
        Returns:
        the positive literals of this assignment
      • negativeLiterals

        public List<Literal> negativeLiterals()
        Returns the negative literals of this assignment.
        Returns:
        the negative literals of this assignment
      • negativeVariables

        public List<Variable> negativeVariables()
        Returns the negative literals of this assignment as variables.
        Returns:
        the negative literals of this assignment
      • literals

        public SortedSet<Literal> literals()
        Returns all literals of this assignment.
        Returns:
        all literals of this assignment
      • addLiteral

        public void addLiteral​(Literal lit)
        Add a single literal to this assignment.
        Parameters:
        lit - the literal
      • evaluateLit

        public boolean evaluateLit​(Literal lit)
        Evaluates a given literal. A literal not covered by the assignment evaluates to false if it is positive, otherwise it evaluates to true.
        Parameters:
        lit - the literal
        Returns:
        the evaluation of the literal
      • restrictLit

        public Formula restrictLit​(Literal lit)
        Restricts a given literal to a constant. Returns the literal itself, if the literal's variable is not known.
        Parameters:
        lit - the literal
        Returns:
        the restriction of the literal or the literal itself, if the literal's variable is not known
      • formula

        public Formula formula​(FormulaFactory f)
        Returns the assignment as a formula.
        Parameters:
        f - the formula factory
        Returns:
        the assignment as a formula
      • blockingClause

        public Formula blockingClause​(FormulaFactory f)
        Creates the blocking clause for this assignment.
        Parameters:
        f - the formula factory
        Returns:
        the blocking clause for this assignment
      • blockingClause

        public Formula blockingClause​(FormulaFactory f,
                                      Collection<? extends Literal> literals)
        Creates the blocking clause for this assignment wrt. a given set of literals. If the set is null, all literals are considered relevant.
        Parameters:
        f - the formula factory
        literals - the set of literals
        Returns:
        the blocking clause for this assignment
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object